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-q-sequence.wiki

75 lines · 1535 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 10 terms:"
9text th "the 1000th term: "
10text fl "terms up to the 100000th that are less than the term before: "
11note q n is Q(n) for n = 1..100000; Q(n) < n here, so every index n - Q(n-1) and n - Q(n-2) is in range
12global q ulong 100001
13note emit writes every byte of a to stdout; a short write is retried, an error exits 1
14fn emit a view uchar * to void
15o = ulong 0
16while lt o len a bound 4096
17k = write 1 a o sub len a o
18if le k 0
19exit 1
20end
21o = add o ulong k
22end
23end
24note emitu writes n in decimal; 20 digits hold every ulong
25fn emitu n ulong to void
26d = new uchar 20 0
27i = ulong 20
28v = n
29while true bound 20
30i = sub i 1
31put d i uchar add rem v 10 48
32v = div v 10
33if eq v 0
34break
35end
36end
37emit part d i sub 20 i
38end
39fn main to int
40put q 1 1
41put q 2 1
42for i ulong 99998
43n = add i 3
44a = get q sub n get q sub n 1
45b = get q sub n get q sub n 2
46put q n add a b
47end
48emit first
49for i ulong 10
50emit sp
51emitu get q add i 1
52end
53emit nl
54emit th
55emitu get q 1000
56emit nl
57c = ulong 0
58for i ulong 99999
59n = add i 2
60if lt get q n get q sub n 1
61c = add c 1
62end
63end
64emit fl
65emitu c
66emit nl
67ret 0
68end
69</syntaxhighlight>
70{{out}}
71<pre>
72first 10 terms: 1 1 2 3 3 4 5 5 6 6
73the 1000th term: 502
74terms up to the 100000th that are less than the term before: 49798
75</pre>