Created
January 14, 2022 21:57
-
-
Save iammateus/e3f61e088b39d7d09349d106f572ee6e 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
(ns tutorial.fibonacci | |
(:gen-class)) | |
(defn fibonacci | |
"Returns the fibonacci sequence of a given length" | |
[ len ] | |
(def fibonacci-sec (atom (seq [ 0 1 ]))) | |
(dotimes [counter (- len 2)] | |
(def first-num (nth @fibonacci-sec counter)) | |
(def sec-num (nth @fibonacci-sec (+ counter 1))) | |
(def new-fibonacci-sec (concat @fibonacci-sec (seq [ (+ first-num sec-num) ]))) | |
(reset! fibonacci-sec new-fibonacci-sec) | |
) | |
(take len @fibonacci-sec)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment