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

92 lines · 1854 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 61 terms:"
9text rec "first term of each decimal length, below index 1000000:\n"
10text fu "fusc("
11text eqs ") = "
12note fu n is fusc(n) for n below 10^6
13global fs ulong 1000000
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
40fn digits n ulong to ulong
41k = ulong 1
42v = div n 10
43while gt v 0 bound 20
44k = add k 1
45v = div v 10
46end
47ret k
48end
49note fusc(0) = 0, fusc(1) = 1, fusc(2n) = fusc(n), fusc(2n+1) = fusc(n) + fusc(n+1); each needs only smaller indices
50fn main to int
51put fs 1 1
52for i ulong 999998
53n = add i 2
54h = shr n 1
55if eq rem n 2 0
56put fs n get fs h
57else
58put fs n add get fs h get fs add h 1
59end
60end
61emit first
62for i ulong 61
63emit sp
64emitu get fs i
65end
66emit nl
67emit rec
68w = ulong 0
69for n ulong 1000000
70d = digits get fs n
71if gt d w
72w = d
73emit fu
74emitu n
75emit eqs
76emitu get fs n
77emit nl
78end
79end
80ret 0
81end
82</syntaxhighlight>
83{{out}}
84<pre>
85first 61 terms: 0 1 1 2 1 3 2 3 1 4 3 5 2 5 3 4 1 5 4 7 3 8 5 7 2 7 5 8 3 7 4 5 1 6 5 9 4 11 7 10 3 11 8 13 5 12 7 9 2 9 7 12 5 13 8 11 3 10 7 11 4
86first term of each decimal length, below index 1000000:
87fusc(0) = 0
88fusc(37) = 11
89fusc(1173) = 108
90fusc(35499) = 1076
91fusc(699051) = 10946
92</pre>