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 / proper-divisors.wiki

93 lines · 1711 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 " "
8text col ":"
9text most "the number in 1..20000 with the most proper divisors: "
10text has " has "
11text pd " proper divisors\n"
12note nd n counts the proper divisors of n, for n up to 20000
13global nd ulong 20001
14note emit writes every byte of a to stdout; a short write is retried, an error exits 1
15fn emit a view uchar * to void
16o = ulong 0
17while lt o len a bound 4096
18k = write 1 a o sub len a o
19if le k 0
20exit 1
21end
22o = add o ulong k
23end
24end
25note emitu writes n in decimal; 20 digits hold every ulong
26fn emitu n ulong to void
27d = new uchar 20 0
28i = ulong 20
29v = n
30while true bound 20
31i = sub i 1
32put d i uchar add rem v 10 48
33v = div v 10
34if eq v 0
35break
36end
37end
38emit part d i sub 20 i
39end
40fn main to int
41note proper divisors of 1..10 by trial over 1..n-1
42for i ulong 10
43n = add i 1
44emitu n
45emit col
46for j ulong i
47d = add j 1
48if eq rem n d 0
49emit sp
50emitu d
51end
52end
53emit nl
54end
55note each d counts once for each multiple 2d, 3d, ... up to 20000; fewer than 20000 multiples per d
56d = ulong 1
57while le d 10000 bound 10000
58j = mul d 2
59while le j 20000 bound 20000
60put nd j add get nd j 1
61j = add j d
62end
63d = add d 1
64end
65b = ulong 1
66for i ulong 20000
67n = add i 1
68if gt get nd n get nd b
69b = n
70end
71end
72emit most
73emitu b
74emit has
75emitu get nd b
76emit pd
77ret 0
78end
79</syntaxhighlight>
80{{out}}
81<pre>
821:
832: 1
843: 1
854: 1 2
865: 1
876: 1 2 3
887: 1
898: 1 2 4
909: 1 3
9110: 1 2 5
92the number in 1..20000 with the most proper divisors: 15120 has 79 proper divisors
93</pre>