Skip to content

Instantly share code, notes, and snippets.

/fib.p6 Secret

Created December 16, 2014 10:53
Show Gist options
  • Save anonymous/ed88c74a3f924ded9ba7 to your computer and use it in GitHub Desktop.
Save anonymous/ed88c74a3f924ded9ba7 to your computer and use it in GitHub Desktop.
fibonacci in perl6 (for advent calendar)
use v6;
sub fibonacci (int $n --> int) {
my int $x = 1;
my int $y = 1;
while $n > 0 {
$x = $x + $y;
$y = $x - $y;
$n = $n - 1;
}
return $y;
}
for ^40 -> int $x {
say fibonacci $x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment