summaryrefslogtreecommitdiffstats
path: root/2.pl
diff options
context:
space:
mode:
Diffstat (limited to '2.pl')
-rwxr-xr-x2.pl18
1 files changed, 18 insertions, 0 deletions
diff --git a/2.pl b/2.pl
new file mode 100755
index 0000000..6b59aed
--- /dev/null
+++ b/2.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";