interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / si / rosetta / tasks / amicable-pairs / amicable-pairs.om

60 lines · 1152 bytes Raw Blame History
1note Rosetta Code task "Amicable pairs": https://rosettacode.org/wiki/Amicable_pairs
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text sp " "
6note ds n is the sum of the proper divisors of n, for n below 20000
7global ds ulong 20000
8note emit writes every byte of a to stdout; a short write is retried, an error exits 1
9fn emit a view uchar * to void
10o = ulong 0
11while lt o len a bound 4096
12k = write 1 a o sub len a o
13if le k 0
14exit 1
15end
16o = add o ulong k
17end
18end
19note emitu writes n in decimal; 20 digits hold every ulong
20fn emitu n ulong to void
21d = new uchar 20 0
22i = ulong 20
23v = n
24while true bound 20
25i = sub i 1
26put d i uchar add rem v 10 48
27v = div v 10
28if eq v 0
29break
30end
31end
32emit part d i sub 20 i
33end
34note each i adds itself to its multiples 2i, 3i, ... below 20000; fewer than 20000 multiples per i
35fn sieve to void
36i = ulong 1
37while lt i 10000 bound 10000
38j = mul i 2
39while lt j 20000 bound 20000
40put ds j add get ds j i
41j = add j i
42end
43i = add i 1
44end
45end
46fn main to int
47sieve
48for n ulong 20000
49m = get ds n
50if and gt m n lt m 20000
51if eq get ds m n
52emitu n
53emit sp
54emitu m
55emit nl
56end
57end
58end
59ret 0
60end