summaryrefslogtreecommitdiffstats
path: root/002.pl
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-05-14 19:51:41 -0500
committerJesse Luehrs <doy@tozt.net>2009-05-14 19:51:41 -0500
commitc3ff98ee4aa79bcaa07c8a478e96539c2a512e73 (patch)
tree0b1a04ee7e5b05ec23dcfa274d4258f8acbcdf9d /002.pl
parent394121b98178246a0b1063e9104f8878cf2a17e5 (diff)
downloadprojecteuler-c3ff98ee4aa79bcaa07c8a478e96539c2a512e73.tar.gz
projecteuler-c3ff98ee4aa79bcaa07c8a478e96539c2a512e73.zip
rename files for better sorting
Diffstat (limited to '002.pl')
-rwxr-xr-x002.pl18
1 files changed, 18 insertions, 0 deletions
diff --git a/002.pl b/002.pl
new file mode 100755
index 0000000..6b59aed
--- /dev/null
+++ b/002.pl
@@ -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";