Project Euler Problem 2
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.
相変わらず解ければいいというスタンスで.
a <- c(1,2) while (a[length(a)] < 4000000){ a <- c(a,a[length(a)]+a[length(a)-1]) } a <- a[1:length(a)-1] sum(a[!a%%2])
4613732