fork(1) 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 fib-seq [max]
  7. (if (= max 2)
  8. [1 2]
  9. (conj (fib-seq (dec max)) (reduce + (take-last 2 (fib-seq (dec max)))))))
  10. ; (if (= max 2)
  11. ; ('(1 2))
  12. ; (do
  13. ; (def prev-seq (fib-seq (dec max)))
  14. ; (conj prev-seq (+ (take-last 2 prev-seq))))))
  15. (print (fib-seq 10))
Success #stdin #stdout 1.55s 389120KB
stdin
Standard input is empty
stdout
[1 2 3 5 8 13 21 34 55 89]