fork download
  1. ; Each new term in the Fibonacci sequence is generated by adding the previous
  2. ; two terms. By starting with 1 and 2, the first 10 terms will be:
  3. ; 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
  4. ; By considering the terms in the Fibonacci sequence whose values do not exceed
  5. ; four million, find the sum of the even-valued terms.
  6. (defn next-fib-num [seq]
  7. (reduce + (take-last 2 seq)))
  8. (defn fib-seq-to [max]
  9. (loop [seq [1 2]]
  10. (if (>= (last seq) max)
  11. (butlast seq)
  12. (recur (conj seq (next-fib-num seq))))))
  13. (println (reduce + (filter even? (fib-seq-to 4000000))))
Success #stdin #stdout 1.5s 390144KB
stdin
Standard input is empty
stdout
4613732