Created
January 10, 2012 22:37
-
-
Save Nican/1591641 to your computer and use it in GitHub Desktop.
Find even fibonacci numbers
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
;;Returns the next even fibbonaci number | |
;; F[n] = 3*F[n-1] + 4*F[n-2] + 5F[n-3] + ... + (x+2)*F[n-x] | |
(defn evenfib-next [seq] | |
(letfn getsum [seq count] | |
(cond | |
(empty? seq) 0 | |
:else (+ | |
(* count (first seq)) | |
(getsum (rest seq) (+ count 1))))) | |
(cons (getsum seq 3) seq) | |
) | |
;Output: ([8 2] (32 8 2) (138 32 8 2) (594 138 32 8 2) (2556 594 138 32 8 2) (10998 2556 594 138 32 8 2)) | |
; 8 and 2 are the first 2 even fibbo numebers | |
(print (take 6 (iterate evenfib-next [8 2]))) | |
;Want: (10998 2556 594 138 32 8 2) | |
;Instead of creating a list of lists, some kind of function that just appends the list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment