interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / exercises / perfect-numbers / .meta / example.om

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