Skip to content

Instantly share code, notes, and snippets.

@melklein
Created June 27, 2016 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melklein/acec538dcc120ca2c66c633bcd0f0a2b to your computer and use it in GitHub Desktop.
Save melklein/acec538dcc120ca2c66c633bcd0f0a2b to your computer and use it in GitHub Desktop.
clojure recursion with 'mundane' recursion and fibonacci numbers
(defn fib-seq [x result]
(if (= x 0)
(reverse result)
(let [next-fib (reduce + (take 2 result))]
(fib-seq (dec x) (conj result next-fib)))))
(defn fib [mx]
(fib-seq (- mx 2) '(1 1)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment