Name: !BBCdr/ZfzM 2011-07-13 1:04
Criticism of my code and discussion about the problem are welcome.
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, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
__________________________________________________
I'm sure /prague/ can find at least one way my solution is crappy. Have at it!
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, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
__________________________________________________
(defun euler2 (max)
(labels ((next-fib (term1 term2 acc)
(if (> (+ term1 term2) max)
(return-from next-fib acc))
(if (evenp (+ term1 term2))
(next-fib (+ term1 term2) term1 (+ acc term1 term2))
(next-fib (+ term1 term2) term1 acc))))
(next-fib 1 1 0)))I'm sure /prague/ can find at least one way my solution is crappy. Have at it!