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 / factors-of-an-integer.wiki

85 lines · 2056 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 pre "factors of "
9text col ":"
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 divisors d with d * d <= n come out ascending; their partners n / d, read back in reverse, finish the list
37note bound: the largest n here is 600851475143, so d stays below 775147, and no n has more than 64 small divisors
38fn tell n ulong to void
39lo = new ulong 64 0
40k = ulong 0
41d = ulong 1
42while le mul d d n bound 999999
43if eq rem n d 0
44put lo k d
45k = add k 1
46end
47d = add d 1
48end
49emit pre
50emitu n
51emit col
52for i ulong k
53emit sp
54emitu get lo i
55end
56for i ulong k
57e = get lo sub sub k 1 i
58if ne mul e e n
59emit sp
60emitu div n e
61end
62end
63emit nl
64end
65fn main to int
66tell 1
67tell 45
68tell 53
69tell 64
70tell 720
71tell 1000000
72tell 600851475143
73ret 0
74end
75</syntaxhighlight>
76{{out}}
77<pre>
78factors of 1: 1
79factors of 45: 1 3 5 9 15 45
80factors of 53: 1 53
81factors of 64: 1 2 4 8 16 32 64
82factors of 720: 1 2 3 4 5 6 8 9 10 12 15 16 18 20 24 30 36 40 45 48 60 72 80 90 120 144 180 240 360 720
83factors of 1000000: 1 2 4 5 8 10 16 20 25 32 40 50 64 80 100 125 160 200 250 320 400 500 625 800 1000 1250 1600 2000 2500 3125 4000 5000 6250 8000 10000 12500 15625 20000 25000 31250 40000 50000 62500 100000 125000 200000 250000 500000 1000000
84factors of 600851475143: 1 71 839 1471 6857 59569 104441 486847 1234169 5753023 10086647 87625999 408464633 716151937 8462696833 600851475143
85</pre>