Created
January 22, 2013 04:17
-
-
Save tailriver/4592003 to your computer and use it in GitHub Desktop.
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/env perl | |
use strict; | |
use warnings; | |
my @series = (0, 1); | |
my $f42 = fibonacci(42); | |
my $f43 = fibonacci(43); | |
print_count(42, 144); | |
print_count($f42, $f43); | |
exit; | |
sub fibonacci { | |
my $i = shift; | |
return $series[$i] if $#series >= $i; | |
$series[$i] = fibonacci($i-2) + fibonacci($i-1); | |
return $series[$i]; | |
} | |
sub count { | |
my($h, $w) = @_; | |
die "error: height[$h] must be less than width[$w]\n" if $h >= $w; | |
return $w % $h ? count($w % $h, $h) + 1 : 0; | |
} | |
sub print_count { | |
my($h, $w) = @_; | |
printf "%dx%d = %d\n", $h, $w, count($h, $w); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment