Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/si/rosetta/tasks/fibonacci-n-step-number-sequences/fibonacci-n-step-number-sequences.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / si / rosetta / tasks / fibonacci-n-step-number-sequences / fibonacci-n-step-number-sequences.om` 88 lines ยท 1613 bytes Raw Blame History 1 note Rosetta Code task "Fibonacci n-step number sequences": https://rosettacode.org/wiki/Fibonacci_n-step_number_sequences 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 om2 4 text nl "\n" 5 text sp " " 6 text t2 "fibonacci: " 7 text t3 "tribonacci:" 8 text t4 "tetranacci:" 9 text t5 "pentanacci:" 10 text t6 "hexanacci: " 11 text t7 "heptanacci:" 12 text t8 "octonacci: " 13 text t9 "nonanacci: " 14 text t10 "decanacci: " 15 text tl "lucas: " 16 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 17 fn emit a view uchar * to void 18 o = ulong 0 19 while lt o len a bound 4096 20 k = write 1 a o sub len a o 21 if le k 0 22 exit 1 23 end 24 o = add o ulong k 25 end 26 end 27 note emitu writes n in decimal; 20 digits hold every ulong 28 fn emitu n ulong to void 29 d = new uchar 20 0 30 i = ulong 20 31 v = n 32 while true bound 20 33 i = sub i 1 34 put d i uchar add rem v 10 48 35 v = div v 10 36 if eq v 0 37 break 38 end 39 end 40 emit part d i sub 20 i 41 end 42 note the n-step sequence starts 1, 1, 2, 4, ..., 2^(n-2) (the n-step seeds) and then each term sums the 43 note previous n; the Lucas numbers are the 2-step sequence seeded 2, 1. 15 terms, all below 2^15 * 15 44 fn seq n ulong s0 ulong s1 ulong to void 45 a = new ulong 15 0 46 put a 0 s0 47 put a 1 s1 48 for i ulong 13 49 k = add i 2 50 s = ulong 0 51 if le k sub n 1 52 s = shl ulong 1 sub k 1 53 else 54 for j ulong n 55 s = add s get a sub sub k 1 j 56 end 57 end 58 put a k s 59 end 60 for i ulong 15 61 emit sp 62 emitu get a i 63 end 64 emit nl 65 end 66 fn main to int 67 emit t2 68 seq 2 1 1 69 emit t3 70 seq 3 1 1 71 emit t4 72 seq 4 1 1 73 emit t5 74 seq 5 1 1 75 emit t6 76 seq 6 1 1 77 emit t7 78 seq 7 1 1 79 emit t8 80 seq 8 1 1 81 emit t9 82 seq 9 1 1 83 emit t10 84 seq 10 1 1 85 emit tl 86 seq 2 2 1 87 ret 0 88 end