Skip to content

Instantly share code, notes, and snippets.

@hroi
Created February 23, 2010 15:23
Show Gist options
  • Save hroi/312291 to your computer and use it in GitHub Desktop.
Save hroi/312291 to your computer and use it in GitHub Desktop.
; Problem 2:
; Find the sum of all the even-valued terms in the Fibonacci
; sequence which do not exceed four million.
(defn nextfib [[x y]]
(cond (zero? x) [1 1]
:else [y (+ x y)]))
(def fibs (map first (iterate nextfib [0 nil])))
(def even-fibs-lt-4mil
(filter even?
(take-while #(< % 4000000 ) fibs)))
(apply + even-fibs-lt-4mil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment