Skip to content

@rubysolo /fibs.clj
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
; 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
Something went wrong with that request. Please try again.