omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / exercises / perfect-numbers / .meta / example.om
| 1 | note Exercism-style exercise "perfect-numbers": https://exercism.org/tracks/python/exercises/perfect-numbers |
| 2 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | note classify compares n with its aliquot sum (the sum of its divisors other than n): 1 perfect |
| 4 | note (equal), 2 abundant (greater), 3 deficient (smaller), 0 when n is not a positive integer. |
| 5 | note Check it with: sh exercise.sh exercises/perfect-numbers |
| 6 | om2 |
| 7 | fn classify n long to int |
| 8 | if le n 0 |
| 9 | ret 0 |
| 10 | end |
| 11 | s = long 0 |
| 12 | d = long 1 |
| 13 | while le mul d d n bound 999999 |
| 14 | if eq rem n d 0 |
| 15 | if ne d n |
| 16 | s = add s d |
| 17 | end |
| 18 | e = div n d |
| 19 | if and ne e d ne e n |
| 20 | s = add s e |
| 21 | end |
| 22 | end |
| 23 | d = add d 1 |
| 24 | end |
| 25 | if eq s n |
| 26 | ret 1 |
| 27 | end |
| 28 | if gt s n |
| 29 | ret 2 |
| 30 | end |
| 31 | ret 3 |
| 32 | end |