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 / hofstadter-figure-figure-sequences.wiki

110 lines · 2118 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 "R(1) to R(10):"
9text chk "first 40 R and first 960 S cover 1..1000 exactly once: "
10text yes "yes\n"
11text no "no\n"
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 R(1) = 1, S(1) = 2, R(n) = R(n-1) + S(n-1), S(n) = the least integer above S(n-1) not in R
39note r holds R(1..50) (R(50) = 1509 > 1000, so every R value up to 1000 is marked in ir); s holds S(1..960)
40fn main to int
41r = new ulong 51 0
42s = new ulong 961 0
43ir = new uchar 1600 0
44put r 1 1
45put s 1 2
46put ir 1 1
47for i ulong 49
48n = add i 2
49v = add get r sub n 1 get s sub n 1
50put r n v
51put ir v 1
52c = add get s sub n 1 1
53while eq get ir c 1 bound 2
54c = add c 1
55end
56put s n c
57end
58note S as the complement of R, now that R is known through 1509: the k-th unmarked integer is S(k)
59k = ulong 0
60c = ulong 1
61while lt k 960 bound 1600
62if eq get ir c 0
63k = add k 1
64put s k c
65end
66c = add c 1
67end
68emit first
69for i ulong 10
70emit sp
71emitu get r add i 1
72end
73emit nl
74cnt = new ulong 1001 0
75ok = ulong 1
76for i ulong 40
77v = get r add i 1
78if gt v 1000
79ok = ulong 0
80else
81put cnt v add get cnt v 1
82end
83end
84for i ulong 960
85v = get s add i 1
86if gt v 1000
87ok = ulong 0
88else
89put cnt v add get cnt v 1
90end
91end
92for i ulong 1000
93if ne get cnt add i 1 1
94ok = ulong 0
95end
96end
97emit chk
98if eq ok 1
99emit yes
100else
101emit no
102end
103ret 0
104end
105</syntaxhighlight>
106{{out}}
107<pre>
108R(1) to R(10): 1 3 7 12 18 26 35 45 56 69
109first 40 R and first 960 S cover 1..1000 exactly once: yes
110</pre>