Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: phi div by 0 error

by hdb (Prior)
on Sep 01, 2013 at 14:24 UTC ( #1051804=note: print w/ replies, xml ) Need Help??


in reply to phi div by 0 error

A faster way is to use $phi = (1+sqrt(5))/2;

However, if you insist of using the ratios of Fibonacci numbers (it would have been nice to mention that), then you need to create 20 of them (rather than 10) if you always divide the even numbered ones by the odd numbered ones. So let your first loop run until 20 instead of 10.

UPDATE: A postfix loop solution for you:

use strict; use warnings; my @list = ( 1, 1 ); push @list, $list[-1]+$list[-2] for 0..17; print +($list[2*$_+1] / $list[2*$_]) . "\n" for 0..9;


Comment on Re: phi div by 0 error
Select or Download Code
Re^2: phi div by 0 error
by perlaintdead (Scribe) on Sep 01, 2013 at 14:29 UTC

    thanks. I actually solved this one before saw your post on a hunch because i saw it outputed exactly half of what i was expecting. I'll have to play around with that sqrt trick.

Re^2: phi div by 0 error
by perlaintdead (Scribe) on Sep 01, 2013 at 14:34 UTC

    (1+sqrt(5))/2 came out to 3.23606797749979 AKA not phi

      just needed another parentheses ((sqrt(5)+1)/2)

        or a small re-order

        perl -le ' print ( (1 + sqrt 5) / 2 )'

        Cheers,
        R.

        Pereant, qui ante nos nostra dixerunt!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1051804]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2014-12-28 21:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (182 votes), past polls