Created
January 4, 2015 03:58
-
-
Save RussellAndrewEdson/95c30531351204c5e957 to your computer and use it in GitHub Desktop.
Clojure code to generate the nth Fibonacci number iteratively.
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
(defn fibonacci | |
"Returns the nth Fibonacci number using an iterative process." | |
[n] | |
(loop [current 0N next 1N index 0] | |
(if (= index n) | |
current | |
(recur next (+ current next) (inc index))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment