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 / amicable-pairs.wiki

74 lines · 1368 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 sp " "
8note ds n is the sum of the proper divisors of n, for n below 20000
9global ds ulong 20000
10note emit writes every byte of a to stdout; a short write is retried, an error exits 1
11fn emit a view uchar * to void
12o = ulong 0
13while lt o len a bound 4096
14k = write 1 a o sub len a o
15if le k 0
16exit 1
17end
18o = add o ulong k
19end
20end
21note emitu writes n in decimal; 20 digits hold every ulong
22fn emitu n ulong to void
23d = new uchar 20 0
24i = ulong 20
25v = n
26while true bound 20
27i = sub i 1
28put d i uchar add rem v 10 48
29v = div v 10
30if eq v 0
31break
32end
33end
34emit part d i sub 20 i
35end
36note each i adds itself to its multiples 2i, 3i, ... below 20000; fewer than 20000 multiples per i
37fn sieve to void
38i = ulong 1
39while lt i 10000 bound 10000
40j = mul i 2
41while lt j 20000 bound 20000
42put ds j add get ds j i
43j = add j i
44end
45i = add i 1
46end
47end
48fn main to int
49sieve
50for n ulong 20000
51m = get ds n
52if and gt m n lt m 20000
53if eq get ds m n
54emitu n
55emit sp
56emitu m
57emit nl
58end
59end
60end
61ret 0
62end
63</syntaxhighlight>
64{{out}}
65<pre>
66220 284
671184 1210
682620 2924
695020 5564
706232 6368
7110744 10856
7212285 14595
7317296 18416
74</pre>