Created
August 5, 2012 22:09
-
-
Save flavioribeiro/3267348 to your computer and use it in GitHub Desktop.
dailykata first exercise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
sub fibonacci { | |
my $n = $_[0]; | |
if ($n <= 1) { | |
return $n; | |
} | |
else { | |
return fibonacci($n-1) + fibonacci($n-2); | |
}; | |
} | |
sub assert { | |
if ($_[0] == $_[1]) { | |
print "OK\n"; | |
} else { | |
print "FAIL\n"; | |
} | |
} | |
assert(0, fibonacci(0)); | |
assert(1, fibonacci(1)); | |
assert(1, fibonacci(2)); | |
assert(2, fibonacci(3)); | |
assert(13, fibonacci(7)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment