RosettaCodeData/Task/Fibonacci-sequence/Perl-6/fibonacci-sequence-4.pl6

7 lines
158 B
Raku

sub fib (Int $n --> Int) {
$n > 1 or return $n;
my ($prev, $this) = 0, 1;
($prev, $this) = $this, $this + $prev for 1 ..^ $n;
return $this;
}