Skip to content

Instantly share code, notes, and snippets.

@iammateus
Created January 14, 2022 21:57
Show Gist options
  • Save iammateus/e3f61e088b39d7d09349d106f572ee6e to your computer and use it in GitHub Desktop.
Save iammateus/e3f61e088b39d7d09349d106f572ee6e to your computer and use it in GitHub Desktop.
(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