#!/usr/bin/perl use strict; use warnings; use bignum; print "Fibonnaci Fun\n\n"; print "Pick a number that represents which value of the Fibonnaci sequence you want to start with\n"; print "ie: 1 would be 1, and 2 would be 1, and 3 would be 2 and so on.\n"; print "Your choice: "; chomp (my $start = <>); print "\nNow pick a number to repesent the range you want.\n"; print "If you want to use values 1 through 10 you you need only enter 10,\n"; print "assuming of course you entered 1 above.\n"; print "Your choice: "; chomp(my $range = <>); print "\n"; for my $fibNum ($start .. $start + $range){ my $fibValue1 = fib($fibNum); my $fibValue2 = fib($fibNum - 1); my $phiApprox = $fibNum <= 1 ? '***' : $fibValue1 / $fibValue2; print "$fibValue1 / $fibValue2 = $phiApprox\n"; } my %cache; sub fib { my ($n) = @_; return $n if $n < 2; --$n; return ($cache{$n} ||= fib($n)) + ($cache{$n - 1} ||= fib($n - 1)); }