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 / van-eck-sequence.wiki

68 lines · 1426 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 first "terms 1 to 10:"
9text last "terms 991 to 1000:"
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 a(0) = 0; a(n+1) = n - m where m < n is the last earlier index with a(m) = a(n), else 0
37note ls v is one more than the last index holding v (0: not seen); every term is below 1000, its index
38fn main to int
39a = new ulong 1000 0
40ls = new ulong 1000 0
41for n ulong 999
42v = get a n
43w = get ls v
44if gt w 0
45put a add n 1 sub n sub w 1
46end
47put ls v add n 1
48end
49emit first
50for i ulong 10
51emit sp
52emitu get a i
53end
54emit nl
55emit last
56for i ulong 10
57emit sp
58emitu get a add 990 i
59end
60emit nl
61ret 0
62end
63</syntaxhighlight>
64{{out}}
65<pre>
66terms 1 to 10: 0 0 1 0 2 0 2 2 1 6
67terms 991 to 1000: 4 7 30 25 67 225 488 0 10 136
68</pre>