Skip to content

Instantly share code, notes, and snippets.

@tailriver
Created January 22, 2013 04:17
Show Gist options
  • Save tailriver/4592003 to your computer and use it in GitHub Desktop.
Save tailriver/4592003 to your computer and use it in GitHub Desktop.
#!/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