#!/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)); } #### Fibonnaci Fun Pick a number that represents which value of the Fibonnaci sequence you want to start with ie: 1 would be 1, and 2 would be 1, and 3 would be 2 and so on. Your choice: 90 Now pick a number to repesent the range you want. If you want to use values 1 through 10 you you need only enter 10, assuming of course you entered 1 above. Your choice: 10 2880067194370816120 / 1779979416004714189 = 1.618033988749894848204586834365638117579 4660046610375530309 / 2880067194370816120 = 1.618033988749894848204586834365638117774 7540113804746346429 / 4660046610375530309 = 1.6180339887498948482045868343656381177 12200160415121876738 / 7540113804746346429 = 1.618033988749894848204586834365638117728 19740274219868223167 / 12200160415121876738 = 1.618033988749894848204586834365638117717 31940434634990099905 / 19740274219868223167 = 1.618033988749894848204586834365638117721 51680708854858323072 / 31940434634990099905 = 1.61803398874989484820458683436563811772 83621143489848422977 / 51680708854858323072 = 1.61803398874989484820458683436563811772 135301852344706746049 / 83621143489848422977 = 1.61803398874989484820458683436563811772 218922995834555169026 / 135301852344706746049 = 1.61803398874989484820458683436563811772 354224848179261915075 / 218922995834555169026 = 1.61803398874989484820458683436563811772