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-n-step-number-sequences.wiki

104 lines · 2317 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 t2 "fibonacci: "
9text t3 "tribonacci:"
10text t4 "tetranacci:"
11text t5 "pentanacci:"
12text t6 "hexanacci: "
13text t7 "heptanacci:"
14text t8 "octonacci: "
15text t9 "nonanacci: "
16text t10 "decanacci: "
17text tl "lucas: "
18note emit writes every byte of a to stdout; a short write is retried, an error exits 1
19fn emit a view uchar * to void
20o = ulong 0
21while lt o len a bound 4096
22k = write 1 a o sub len a o
23if le k 0
24exit 1
25end
26o = add o ulong k
27end
28end
29note emitu writes n in decimal; 20 digits hold every ulong
30fn emitu n ulong to void
31d = new uchar 20 0
32i = ulong 20
33v = n
34while true bound 20
35i = sub i 1
36put d i uchar add rem v 10 48
37v = div v 10
38if eq v 0
39break
40end
41end
42emit part d i sub 20 i
43end
44note the n-step sequence starts 1, 1, 2, 4, ..., 2^(n-2) (the n-step seeds) and then each term sums the
45note previous n; the Lucas numbers are the 2-step sequence seeded 2, 1. 15 terms, all below 2^15 * 15
46fn seq n ulong s0 ulong s1 ulong to void
47a = new ulong 15 0
48put a 0 s0
49put a 1 s1
50for i ulong 13
51k = add i 2
52s = ulong 0
53if le k sub n 1
54s = shl ulong 1 sub k 1
55else
56for j ulong n
57s = add s get a sub sub k 1 j
58end
59end
60put a k s
61end
62for i ulong 15
63emit sp
64emitu get a i
65end
66emit nl
67end
68fn main to int
69emit t2
70seq 2 1 1
71emit t3
72seq 3 1 1
73emit t4
74seq 4 1 1
75emit t5
76seq 5 1 1
77emit t6
78seq 6 1 1
79emit t7
80seq 7 1 1
81emit t8
82seq 8 1 1
83emit t9
84seq 9 1 1
85emit t10
86seq 10 1 1
87emit tl
88seq 2 2 1
89ret 0
90end
91</syntaxhighlight>
92{{out}}
93<pre>
94fibonacci: 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610
95tribonacci: 1 1 2 4 7 13 24 44 81 149 274 504 927 1705 3136
96tetranacci: 1 1 2 4 8 15 29 56 108 208 401 773 1490 2872 5536
97pentanacci: 1 1 2 4 8 16 31 61 120 236 464 912 1793 3525 6930
98hexanacci: 1 1 2 4 8 16 32 63 125 248 492 976 1936 3840 7617
99heptanacci: 1 1 2 4 8 16 32 64 127 253 504 1004 2000 3984 7936
100octonacci: 1 1 2 4 8 16 32 64 128 255 509 1016 2028 4048 8080
101nonanacci: 1 1 2 4 8 16 32 64 128 256 511 1021 2040 4076 8144
102decanacci: 1 1 2 4 8 16 32 64 128 256 512 1023 2045 4088 8172
103lucas: 2 1 3 4 7 11 18 29 47 76 123 199 322 521 843
104</pre>