Skip to content

Instantly share code, notes, and snippets.

@felipernb
Created August 5, 2012 22:42
Show Gist options
  • Save felipernb/3267614 to your computer and use it in GitHub Desktop.
Save felipernb/3267614 to your computer and use it in GitHub Desktop.
fibonacci in perl
#!/usr/bin/perl
# O(n) in time, O(1) in space
sub fib {
my $n = $_[0];
my $a = 0;
my $b = 1;
for ($i = 0; $i < $n; $i++) {
($a, $b) = ($a+$b, $a);
}
return $a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment