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 / perfect-numbers.wiki

67 lines · 1148 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"
7note emit writes every byte of a to stdout; a short write is retried, an error exits 1
8fn emit a view uchar * to void
9o = ulong 0
10while lt o len a bound 4096
11k = write 1 a o sub len a o
12if le k 0
13exit 1
14end
15o = add o ulong k
16end
17end
18note emitu writes n in decimal; 20 digits hold every ulong
19fn emitu n ulong to void
20d = new uchar 20 0
21i = ulong 20
22v = n
23while true bound 20
24i = sub i 1
25put d i uchar add rem v 10 48
26v = div v 10
27if eq v 0
28break
29end
30end
31emit part d i sub 20 i
32end
33note sum of proper divisors, pairing d with n / d up to the square root
34fn perfect n ulong to bool
35if lt n 2
36ret false
37end
38s = ulong 1
39d = ulong 2
40while le mul d d n bound 1000
41if eq rem n d 0
42s = add s d
43if ne mul d d n
44s = add s div n d
45end
46end
47d = add d 1
48end
49ret eq s n
50end
51fn main to int
52for i ulong 10000
53if perfect i
54emitu i
55emit nl
56end
57end
58ret 0
59end
60</syntaxhighlight>
61{{out}}
62<pre>
636
6428
65496
668128
67</pre>