Created
April 28, 2011 21:43
-
-
Save rubysolo/947410 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
; return sequence of first n fibonacci numbers: | |
(defn fibs [n] | |
(case n | |
0 '() | |
1 '(1) | |
2 '(1 1) | |
(let [ | |
x (- n 1) | |
y (- n 2) | |
z (- n 3) | |
s (fibs x) | |
] | |
(concat s [(+ (nth s y) (nth s z))]) | |
) | |
) | |
) | |
; repl output: | |
;user=> user=> (= (fibs 3) '(1 1 2)) | |
;true | |
;user=> (= (fibs 6) '(1 1 2 3 5 8)) | |
;true | |
;user=> (= (fibs 8) '(1 1 2 3 5 8 13 21)) | |
;true | |
;--- | |
; 4clojure error: | |
; (used above function definition with 'fn' rather than 'defn') | |
; java.security.PrivilegedActionException: java.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to clojure.lang.MapEntry (NO_SOURCE_FILE:0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment