Fibonacci n-step number sequences: Difference between revisions

Removed first D entry
(+ two D versions)
(Removed first D entry)
Line 46:
 
=={{header|D}}==
<lang d>import std.stdio, std.algorithm, std.range, std.conv, std.functional;
 
void main() {
int[] head;
int fibber(in size_t n) /*nothrow*/ {
alias memoize!fibber f;
if (n < head.length)
return head[n];
return iota(n - head.length, n).map!f().reduce!q{a + b}();
}
 
head = [1, 1];
iota(10).map!fibber().writeln();
head = [2, 1];
iota(10).map!fibber().writeln();
 
auto prefixes = "fibo tribo tetra penta hexa hepta octo nona deca";
foreach (n, name; zip(iota(2, 11), prefixes.split())) {
head = [1] ~ iota(n-1).map!q{2 ^^ a}().array();
const items = iota(15).map!(i => text(fibber(i)))().join(" ");
writefln("n=%2d, %5snacci -> %s ...", n, name, items);
}
}</lang>
{{out}}
<pre>[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
[2, 1, 2, 3, 5, 8, 13, 21, 34, 55]
n= 2, fibonacci -> 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 ...
n= 3, tribonacci -> 1 1 2 4 6 10 16 26 42 68 110 178 288 466 754 ...
n= 4, tetranacci -> 1 1 2 4 7 11 18 29 47 76 123 199 322 521 843 ...
n= 5, pentanacci -> 1 1 2 4 8 12 19 31 50 81 131 212 343 555 898 ...
n= 6, hexanacci -> 1 1 2 4 8 16 20 32 52 84 136 220 356 576 932 ...
n= 7, heptanacci -> 1 1 2 4 8 16 32 33 53 86 139 225 364 589 953 ...
n= 8, octonacci -> 1 1 2 4 8 16 32 64 54 87 141 228 369 597 966 ...
n= 9, nonanacci -> 1 1 2 4 8 16 32 64 128 88 142 230 372 602 974 ...
n=10, decanacci -> 1 1 2 4 8 16 32 64 128 256 143 231 374 605 979 ...</pre>
===Alternative Version===
The output is similar.
<lang d>import std.stdio, std.algorithm, std.range, std.conv;
 
Line 131 ⟶ 94:
}
}</lang>
{{out}}
<pre>[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
2 1 3 4 7 11 18 29 47 76
n= 2, fibonacci -> 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 ...
n= 3, tribonacci -> 1 1 2 4 67 1013 1624 2644 4281 68149 110274 178504 288927 4661705 7543136 ...
n= 4, tetranacci -> 1 1 2 4 78 11 1815 29 4756 108 76208 123401 199773 3221490 5212872 8435536 ...
n= 5, pentanacci -> 1 1 2 4 8 12 1916 31 5061 120 81236 131464 212912 3431793 5553525 8986930 ...
n= 6, hexanacci -> 1 1 2 4 8 16 20 32 5263 125 84248 136492 220976 3561936 5763840 9327617 ...
n= 7, heptanacci -> 1 1 2 4 8 16 32 3364 53127 86253 139504 2251004 3642000 5893984 9537936 ...
n= 8, octonacci -> 1 1 2 4 8 16 32 64 54128 87255 141509 2281016 3692028 5974048 9668080 ...
n= 9, nonanacci -> 1 1 2 4 8 16 32 64 128 88256 142511 2301021 3722040 6024076 9748144 ...
n=10, decanacci -> 1 1 2 4 8 16 32 64 128 256 143512 2311023 3742045 6054088 9798172 ...</pre>
 
=={{header|Python}}==