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

92 lines · 1669 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 minus "-"
9text tfirst "first 20: "
10text tnth "1691st: "
11global ham ulong 1691
12note emit writes every byte of a to stdout; a short write is retried, an error exits 1
13fn emit a view uchar * to void
14o = ulong 0
15while lt o len a bound 4096
16k = write 1 a o sub len a o
17if le k 0
18exit 1
19end
20o = add o ulong k
21end
22end
23note emitu writes n in decimal; 20 digits hold every ulong
24fn emitu n ulong to void
25d = new uchar 20 0
26i = ulong 20
27v = n
28while true bound 20
29i = sub i 1
30put d i uchar add rem v 10 48
31v = div v 10
32if eq v 0
33break
34end
35end
36emit part d i sub 20 i
37end
38note Dijkstra's method: three indices into the list already built point at the smallest numbers whose
39note double, triple and quintuple are not yet listed; the next number is the least of the three
40fn min3 a ulong b ulong c ulong to ulong
41m = a
42if lt b m
43m = b
44end
45if lt c m
46m = c
47end
48ret m
49end
50fn build n ulong to void
51put ham 0 1
52i = ulong 0
53j = ulong 0
54k = ulong 0
55for x ulong sub n 1
56a = mul get ham i 2
57b = mul get ham j 3
58c = mul get ham k 5
59m = min3 a b c
60put ham add x 1 m
61if eq a m
62i = add i 1
63end
64if eq b m
65j = add j 1
66end
67if eq c m
68k = add k 1
69end
70end
71end
72fn main to int
73build 1691
74emit tfirst
75for i ulong 20
76if gt i 0
77emit sp
78end
79emitu get ham i
80end
81emit nl
82emit tnth
83emitu get ham 1690
84emit nl
85ret 0
86end
87</syntaxhighlight>
88{{out}}
89<pre>
90first 20: 1 2 3 4 5 6 8 9 10 12 15 16 18 20 24 25 27 30 32 36
911691st: 2125764000
92</pre>