mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-26 07:04:27 +00:00
12 lines
382 B
Plaintext
12 lines
382 B
Plaintext
;; Functions to calculate Fibonacci numbers
|
|
|
|
;; Recursive, tail call optimized
|
|
(defn fibRec (i n a b) (if (= i n) (+ a b) (fibRec (inc i) n b (+ a b))))
|
|
(defn fib (n) (if (< n 2) n (fibRec 2 n 0 1)))
|
|
|
|
;; Return a vector of n Fibonacci numbers
|
|
(defn fibVec (n) (map fib (range n)))
|
|
|
|
;; Slow recursive version
|
|
(defn slowFib (n) (if (< n 2) n (+ (slowFib (- n 1)) (slowFib (- n 2)))))
|