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 / oracle.py

16 lines · 789 bytes Raw Blame History
1# Independent reference for "Fibonacci n-step number sequences" (Python 3, standard library only).
2# expected.txt is this program's stdout; omc never produced it.
3names = {2: "fibonacci: ", 3: "tribonacci:", 4: "tetranacci:", 5: "pentanacci:", 6: "hexanacci: ",
4 7: "heptanacci:", 8: "octonacci: ", 9: "nonanacci: ", 10: "decanacci: "}
5def nstep(seed, n, count):
6 a = list(seed)
7 while len(a) < count:
8 a.append(sum(a[-n:]))
9 return a[:count]
10# the n-step sequence is seeded with the first n terms of the (n-1)-step one, starting from 1, 1
11seed = [1, 1]
12for n in range(2, 11):
13 if n > 2:
14 seed = nstep(seed, n - 1, n)
15 print(names[n] + "".join(f" {v}" for v in nstep(seed, n, 15)))
16print("lucas: " + "".join(f" {v}" for v in nstep([2, 1], 2, 15)))