interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / tasks / fibonacci-n-step-number-sequences / fibonacci-n-step-number-sequences.om

88 lines · 1613 bytes Raw Blame History
1note Rosetta Code task "Fibonacci n-step number sequences": https://rosettacode.org/wiki/Fibonacci_n-step_number_sequences
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text sp " "
6text t2 "fibonacci: "
7text t3 "tribonacci:"
8text t4 "tetranacci:"
9text t5 "pentanacci:"
10text t6 "hexanacci: "
11text t7 "heptanacci:"
12text t8 "octonacci: "
13text t9 "nonanacci: "
14text t10 "decanacci: "
15text tl "lucas: "
16note emit writes every byte of a to stdout; a short write is retried, an error exits 1
17fn emit a view uchar * to void
18o = ulong 0
19while lt o len a bound 4096
20k = write 1 a o sub len a o
21if le k 0
22exit 1
23end
24o = add o ulong k
25end
26end
27note emitu writes n in decimal; 20 digits hold every ulong
28fn emitu n ulong to void
29d = new uchar 20 0
30i = ulong 20
31v = n
32while true bound 20
33i = sub i 1
34put d i uchar add rem v 10 48
35v = div v 10
36if eq v 0
37break
38end
39end
40emit part d i sub 20 i
41end
42note the n-step sequence starts 1, 1, 2, 4, ..., 2^(n-2) (the n-step seeds) and then each term sums the
43note previous n; the Lucas numbers are the 2-step sequence seeded 2, 1. 15 terms, all below 2^15 * 15
44fn seq n ulong s0 ulong s1 ulong to void
45a = new ulong 15 0
46put a 0 s0
47put a 1 s1
48for i ulong 13
49k = add i 2
50s = ulong 0
51if le k sub n 1
52s = shl ulong 1 sub k 1
53else
54for j ulong n
55s = add s get a sub sub k 1 j
56end
57end
58put a k s
59end
60for i ulong 15
61emit sp
62emitu get a i
63end
64emit nl
65end
66fn main to int
67emit t2
68seq 2 1 1
69emit t3
70seq 3 1 1
71emit t4
72seq 4 1 1
73emit t5
74seq 5 1 1
75emit t6
76seq 6 1 1
77emit t7
78seq 7 1 1
79emit t8
80seq 8 1 1
81emit t9
82seq 9 1 1
83emit t10
84seq 10 1 1
85emit tl
86seq 2 2 1
87ret 0
88end