diff options
author | Jesse Luehrs <doy@tozt.net> | 2009-05-13 23:32:40 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2009-05-13 23:32:40 -0500 |
commit | 7e7b56db42ceb8d2b8973eae678fa4b58d5d3659 (patch) | |
tree | 7a5cb816809d632e30227c1e39485ed63b500e80 /2.pl | |
download | projecteuler-7e7b56db42ceb8d2b8973eae678fa4b58d5d3659.tar.gz projecteuler-7e7b56db42ceb8d2b8973eae678fa4b58d5d3659.zip |
add old solutions
Diffstat (limited to '2.pl')
-rwxr-xr-x | 2.pl | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -0,0 +1,18 @@ +#!/usr/bin/perl +use strict; +use warnings; + +my $root5 = sqrt 5; +my $phi = (1 + $root5)/2; + +sub fib { int (($phi**$_[0]-(1-$phi)**$_[0])/$root5 + 0.5) } + +my $i = 0; +my $sum = 0; +while (1) { + $i++; + my $n = fib $i; + last if $n > 1000000; + $sum += $n if $n % 2 == 0; +} +print "$sum\n"; |