omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / si / rosetta / exercises / armstrong-numbers / .meta / example.om
| 1 | note Exercism-style exercise "armstrong-numbers": https://exercism.org/tracks/python/exercises/armstrong-numbers |
| 2 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | note Return true when n equals the sum of its digits, each raised to the number of digits. |
| 4 | note Check it with: sh exercise.sh exercises/armstrong-numbers |
| 5 | om2 |
| 6 | fn armstrong n ulong to bool |
| 7 | k = ulong 0 |
| 8 | v = n |
| 9 | while true bound 20 |
| 10 | k = add k 1 |
| 11 | v = div v 10 |
| 12 | if eq v 0 |
| 13 | break |
| 14 | end |
| 15 | end |
| 16 | s = ulong 0 |
| 17 | v = n |
| 18 | for i ulong k |
| 19 | d = rem v 10 |
| 20 | p = ulong 1 |
| 21 | for j ulong k |
| 22 | p = mul p d |
| 23 | end |
| 24 | s = add s p |
| 25 | v = div v 10 |
| 26 | end |
| 27 | ret eq s n |
| 28 | end |