Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/si/rosetta/tasks/hofstadter-q-sequence/hofstadter-q-sequence.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / si / rosetta / tasks / hofstadter-q-sequence / hofstadter-q-sequence.om` 66 lines ยท 1293 bytes Raw Blame History 1 note Rosetta Code task "Hofstadter Q sequence": https://rosettacode.org/wiki/Hofstadter_Q_sequence 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 om2 4 text nl "\n" 5 text sp " " 6 text first "first 10 terms:" 7 text th "the 1000th term: " 8 text fl "terms up to the 100000th that are less than the term before: " 9 note 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 10 global q ulong 100001 11 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 12 fn emit a view uchar * to void 13 o = ulong 0 14 while lt o len a bound 4096 15 k = write 1 a o sub len a o 16 if le k 0 17 exit 1 18 end 19 o = add o ulong k 20 end 21 end 22 note emitu writes n in decimal; 20 digits hold every ulong 23 fn emitu n ulong to void 24 d = new uchar 20 0 25 i = ulong 20 26 v = n 27 while true bound 20 28 i = sub i 1 29 put d i uchar add rem v 10 48 30 v = div v 10 31 if eq v 0 32 break 33 end 34 end 35 emit part d i sub 20 i 36 end 37 fn main to int 38 put q 1 1 39 put q 2 1 40 for i ulong 99998 41 n = add i 3 42 a = get q sub n get q sub n 1 43 b = get q sub n get q sub n 2 44 put q n add a b 45 end 46 emit first 47 for i ulong 10 48 emit sp 49 emitu get q add i 1 50 end 51 emit nl 52 emit th 53 emitu get q 1000 54 emit nl 55 c = ulong 0 56 for i ulong 99999 57 n = add i 2 58 if lt get q n get q sub n 1 59 c = add c 1 60 end 61 end 62 emit fl 63 emitu c 64 emit nl 65 ret 0 66 end