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:My solution, in Haskell:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
f=(scanl(+)0(1:f))Can't get rid of that space, sadly! 57 characters. And newlines count!
s=sum$filter even$takeWhile(<4000000)f
Your shot, Neil.
57. Ignore the dirty 4*10e5 trick. (Ruby)
ReplyDeletex,y,z=1,2,0;(x%2==0?z+=x:0;y+=x;x=y-x;)while x<4*10e5;p z