I solved Euler 1-3 in 2015 but stopped...
#!/usr/bin/env perl use feature qw{say state} ; use bigint; my $max = 4_000_000 ; my $sum = 0 ; while (1){ state $i = 0; $i++; my $f = fibonacci($i); my $e = $f %2==0?1:0; last if $f > $max ; $sum += $f if $e; } say $sum; sub fibonacci { my $i = shift ; state $cache ; $cache->[0]=1; $cache->[1]=1; if ( $cache->[$i] ) { return $cache->[$i] } $cache->[$i] = $cache->[$i-1] + $cache->[$i-2] ; return $cache->[$i] ; }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I solved Euler 1-3 in 2015 but stopped...