interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / drafts / rosettacode / abundant-deficient-and-perfect-number-classifications.wiki

86 lines · 1589 bytes Raw Blame History
1=={{header|Omegese}}==
2{{works with|omc|sha256 2c824805, aien-dev/omega-mv e5b32567, Linux AArch64}}
3Omega has no imports, so the small output helpers (<code>emit</code> and friends) are part of the program.
4<syntaxhighlight lang="text">
5om2
6text nl "\n"
7text tdef "deficient: "
8text tper "perfect: "
9text tabu "abundant: "
10note ds n is the sum of the proper divisors of n, for n up to 20000
11global ds ulong 20001
12note emit writes every byte of a to stdout; a short write is retried, an error exits 1
13fn emit a view uchar * to void
14o = ulong 0
15while lt o len a bound 4096
16k = write 1 a o sub len a o
17if le k 0
18exit 1
19end
20o = add o ulong k
21end
22end
23note emitu writes n in decimal; 20 digits hold every ulong
24fn emitu n ulong to void
25d = new uchar 20 0
26i = ulong 20
27v = n
28while true bound 20
29i = sub i 1
30put d i uchar add rem v 10 48
31v = div v 10
32if eq v 0
33break
34end
35end
36emit part d i sub 20 i
37end
38note each i adds itself to its multiples 2i, 3i, ... up to 20000; fewer than 20000 multiples per i
39fn sieve to void
40i = ulong 1
41while le i 10000 bound 10000
42j = mul i 2
43while le j 20000 bound 20000
44put ds j add get ds j i
45j = add j i
46end
47i = add i 1
48end
49end
50note 1..20000 sorted by comparing each n with the sum of its proper divisors
51fn main to int
52sieve
53d = ulong 0
54p = ulong 0
55a = ulong 0
56for i ulong 20000
57n = add i 1
58s = get ds n
59if lt s n
60d = add d 1
61end
62if eq s n
63p = add p 1
64end
65if gt s n
66a = add a 1
67end
68end
69emit tdef
70emitu d
71emit nl
72emit tper
73emitu p
74emit nl
75emit tabu
76emitu a
77emit nl
78ret 0
79end
80</syntaxhighlight>
81{{out}}
82<pre>
83deficient: 15043
84perfect: 4
85abundant: 4953
86</pre>