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

79 lines · 1322 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"
7note emit writes every byte of a to stdout; a short write is retried, an error exits 1
8fn emit a view uchar * to void
9o = ulong 0
10while lt o len a bound 4096
11k = write 1 a o sub len a o
12if le k 0
13exit 1
14end
15o = add o ulong k
16end
17end
18note emitu writes n in decimal; 20 digits hold every ulong
19fn emitu n ulong to void
20d = new uchar 20 0
21i = ulong 20
22v = n
23while true bound 20
24i = sub i 1
25put d i uchar add rem v 10 48
26v = div v 10
27if eq v 0
28break
29end
30end
31emit part d i sub 20 i
32end
33note fib n is F(n) with F(0) = 0 and F(1) = 1; F(93) is the largest that fits a ulong
34note (the loop computes one term past the one returned; unsigned add wraps, it never traps)
35fn fib n ulong to ulong
36a = ulong 0
37b = ulong 1
38for i ulong n
39t = add a b
40a = b
41b = t
42end
43ret a
44end
45fn main to int
46for n ulong 94
47emitu fib n
48emit nl
49end
50ret 0
51end
52</syntaxhighlight>
53{{out}}
54<pre>
550
561
571
582
593
605
618
6213
6321
6434
6555
6689
67144
68233
69377
70...
71420196140727489673
72679891637638612258
731100087778366101931
741779979416004714189
752880067194370816120
764660046610375530309
777540113804746346429
7812200160415121876738
79</pre>