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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: phi div by 0 error
by perlaintdead (Scribe) on Sep 01, 2013 at 14:29 UTC | |
by hdb (Monsignor) on Sep 01, 2013 at 14:33 UTC | |
|
Re^2: phi div by 0 error
by perlaintdead (Scribe) on Sep 01, 2013 at 14:34 UTC | |
by perlaintdead (Scribe) on Sep 01, 2013 at 14:36 UTC | |
by Random_Walk (Prior) on Sep 02, 2013 at 09:18 UTC |