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

79 lines · 1433 bytes Raw Blame History
1note Rosetta Code task "Fusc sequence": https://rosettacode.org/wiki/Fusc_sequence
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text sp " "
6text first "first 61 terms:"
7text rec "first term of each decimal length, below index 1000000:\n"
8text fu "fusc("
9text eqs ") = "
10note fu n is fusc(n) for n below 10^6
11global fs ulong 1000000
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
38fn digits n ulong to ulong
39k = ulong 1
40v = div n 10
41while gt v 0 bound 20
42k = add k 1
43v = div v 10
44end
45ret k
46end
47note fusc(0) = 0, fusc(1) = 1, fusc(2n) = fusc(n), fusc(2n+1) = fusc(n) + fusc(n+1); each needs only smaller indices
48fn main to int
49put fs 1 1
50for i ulong 999998
51n = add i 2
52h = shr n 1
53if eq rem n 2 0
54put fs n get fs h
55else
56put fs n add get fs h get fs add h 1
57end
58end
59emit first
60for i ulong 61
61emit sp
62emitu get fs i
63end
64emit nl
65emit rec
66w = ulong 0
67for n ulong 1000000
68d = digits get fs n
69if gt d w
70w = d
71emit fu
72emitu n
73emit eqs
74emitu get fs n
75emit nl
76end
77end
78ret 0
79end