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

92 lines · 1811 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 "first 15 terms:"
9text dup "first term already seen: a("
10text eqs ") = "
11text cov "terms a(0)..a(n) first contain every integer 0..1000 at n = "
12note sn v is 1 once v has appeared; the oracle's run shows no term before 0..1000 is covered exceeds 1942300
13global sn uchar 1942301
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
40note a(0) = 0; a(n) = a(n-1) - n if that is positive and new, else a(n-1) + n
41note bound: the cover is complete at n = 328002, below the 999999 loop bound
42fn main to int
43emit first
44emit sp
45emitu 0
46put sn 0 1
47a = ulong 0
48n = ulong 0
49d = ulong 0
50c = ulong 1
51while lt c 1001 bound 999999
52n = add n 1
53nw = add a n
54if gt a n
55if eq get sn sub a n 0
56nw = sub a n
57end
58end
59a = nw
60if eq get sn a 0
61if le a 1000
62c = add c 1
63end
64else
65if eq d 0
66d = n
67emit nl
68emit dup
69emitu n
70emit eqs
71emitu a
72emit nl
73end
74end
75put sn a 1
76if lt n 15
77emit sp
78emitu a
79end
80end
81emit cov
82emitu n
83emit nl
84ret 0
85end
86</syntaxhighlight>
87{{out}}
88<pre>
89first 15 terms: 0 1 3 6 2 7 13 20 12 21 11 22 10 23 9
90first term already seen: a(24) = 42
91terms a(0)..a(n) first contain every integer 0..1000 at n = 328002
92</pre>