Fibonacci n-step number sequences: Difference between revisions

→‎{{header|Perl}}: eliminate hard-coded value
m (→‎{{header|PL/I}}: fixed a misspelling.)
(→‎{{header|Perl}}: eliminate hard-coded value)
Line 3,086:
<lang perl>use strict;
use warnings;
use feature '<say' signatures>;
no warnings 'experimental';
use List::Util <max sum>;
 
sub fib_n ($n = 2, $xs = [1], $max = 100) {
sub fib {
my $n = shift;
my $xs = shift // [1];
my @xs = @$xs;
while ( 20$max > (my $len = @xs) ) {
push @xs, sum @xs[ max($len - $n, 0) .. $len-1 ];
}
Line 3,099 ⟶ 3,098:
}
 
say $_-1 . ': ' . join( ' ', fib(fib_n $_ )[0..19] for 2..10;
say "\nLucas: " . join( ' ', fib fib_n(2, [2,1], 20);</lang>
{{out}}
<pre>1: 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765
2,392

edits