Created
May 6, 2014 20:42
-
-
Save tliff/820203496112568ffb12 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
(defn fib [n] | |
(cond | |
(= 0 n) 1 | |
(= 1 n) 2 | |
:else (+ (fib (- n 2)) (fib (- n 1))) | |
) | |
) | |
(def fibmemo (memoize fib)) | |
(defn upfib [n maxn] ( | |
cond | |
(> (fibmemo n) maxn) [] | |
:else (concat [(fibmemo n)] (upfib (+ n 1) maxn)) | |
) | |
) | |
(pr (reduce + (filter even? (upfib 0 4000000)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment