Created
February 23, 2010 15:23
-
-
Save hroi/312291 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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