omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / tasks / fibonacci-n-step-number-sequences / oracle.py
| 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. |
| 3 | names = {2: "fibonacci: ", 3: "tribonacci:", 4: "tetranacci:", 5: "pentanacci:", 6: "hexanacci: ", |
| 4 | 7: "heptanacci:", 8: "octonacci: ", 9: "nonanacci: ", 10: "decanacci: "} |
| 5 | def 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 |
| 11 | seed = [1, 1] |
| 12 | for 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))) |
| 16 | print("lucas: " + "".join(f" {v}" for v in nstep([2, 1], 2, 15))) |