A slight tidy up:

#!/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 sequ +ence 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)) +; }

Prints (for input numbers 90, 10):

Fibonnaci Fun Pick a number that represents which value of the Fibonnaci sequence yo +u 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.618033988749894848204586 +834365638117579 4660046610375530309 / 2880067194370816120 = 1.618033988749894848204586 +834365638117774 7540113804746346429 / 4660046610375530309 = 1.618033988749894848204586 +8343656381177 12200160415121876738 / 7540113804746346429 = 1.61803398874989484820458 +6834365638117728 19740274219868223167 / 12200160415121876738 = 1.6180339887498948482045 +86834365638117717 31940434634990099905 / 19740274219868223167 = 1.6180339887498948482045 +86834365638117721 51680708854858323072 / 31940434634990099905 = 1.6180339887498948482045 +8683436563811772 83621143489848422977 / 51680708854858323072 = 1.6180339887498948482045 +8683436563811772 135301852344706746049 / 83621143489848422977 = 1.618033988749894848204 +58683436563811772 218922995834555169026 / 135301852344706746049 = 1.61803398874989484820 +458683436563811772 354224848179261915075 / 218922995834555169026 = 1.61803398874989484820 +458683436563811772

You might have noticed the use of bignum btw.


True laziness is hard work

In reply to Re^2: how to speed up program dealing with large numbers? by GrandFather
in thread how to speed up program dealing with large numbers? by Solarplight

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.