Created
May 4, 2014 14:02
-
-
Save bluven/339902c60e6e799f2897 to your computer and use it in GitHub Desktop.
计算某数值以下的偶数fib和
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
(def fib-seq | |
(lazy-cat [0 1] (map + (rest fib-seq) fib-seq))) | |
(def even-fib-seq (filter even? fib-seq)) | |
(defn sum-fib [limit] | |
(loop [i 1 | |
fib-num (nth even-fib-seq i) | |
seqn []] | |
(if (>= fib-num limit) | |
(apply + seqn) | |
(recur (inc i) (nth even-fib-seq (inc i)) (cons fib-num seqn ))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment