interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / si / rosetta / tasks / hofstadter-q-sequence / hofstadter-q-sequence.om

66 lines · 1293 bytes Raw Blame History
1note Rosetta Code task "Hofstadter Q sequence": https://rosettacode.org/wiki/Hofstadter_Q_sequence
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text sp " "
6text first "first 10 terms:"
7text th "the 1000th term: "
8text fl "terms up to the 100000th that are less than the term before: "
9note 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
10global q ulong 100001
11note emit writes every byte of a to stdout; a short write is retried, an error exits 1
12fn emit a view uchar * to void
13o = ulong 0
14while lt o len a bound 4096
15k = write 1 a o sub len a o
16if le k 0
17exit 1
18end
19o = add o ulong k
20end
21end
22note emitu writes n in decimal; 20 digits hold every ulong
23fn emitu n ulong to void
24d = new uchar 20 0
25i = ulong 20
26v = n
27while true bound 20
28i = sub i 1
29put d i uchar add rem v 10 48
30v = div v 10
31if eq v 0
32break
33end
34end
35emit part d i sub 20 i
36end
37fn main to int
38put q 1 1
39put q 2 1
40for i ulong 99998
41n = add i 3
42a = get q sub n get q sub n 1
43b = get q sub n get q sub n 2
44put q n add a b
45end
46emit first
47for i ulong 10
48emit sp
49emitu get q add i 1
50end
51emit nl
52emit th
53emitu get q 1000
54emit nl
55c = ulong 0
56for i ulong 99999
57n = add i 2
58if lt get q n get q sub n 1
59c = add c 1
60end
61end
62emit fl
63emitu c
64emit nl
65ret 0
66end