Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 18 lines (14 sloc) 570 Bytes
#!/usr/bin/perl6
=begin
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
Find the sum of all the even-valued terms in the sequence which do not exceed four million.
=end
my @fib = (1,2); #start the list as stated in the problem
my $stop = 4000000; #where to stop
while 1 { # stop case is in the loop
my $next = @fib[@fib.end-1] + @fib[@fib.end];
last if $next > $stop;
@fib.push( $next );
}
say [+] grep { $_ % 2 == 0 }, @fib;