Skip to content

Instantly share code, notes, and snippets.

@perezd
Created January 29, 2012 21:02
Show Gist options
  • Save perezd/1700633 to your computer and use it in GitHub Desktop.
Save perezd/1700633 to your computer and use it in GitHub Desktop.
; iterative fibonacci technique
; in clojure
(defn fib-step [[a,b]]
[b (+ a b)]
)
(defn fib-seq []
(map first (iterate fib-step [0 1]))
)
(defn fib [n]
(nth (fib-seq) n)
)
; usage
(fib 2000)
; =>
4224696333392304878706725602341482782579852840250681098010280137314308584370130707224123599639141511088446087538909603607640194711643596029271983312598737326253555802606991585915229492453904998722256795316982874482472992263901833716778060607011615497886719879858311468870876264597369086722884023654422295243347964480139515349562972087652656069529806499841977448720155612802665404554171717881930324025204312082516817125
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment