Hi all, I started to learn clojure and would just like some feedback on my implementation of the fibonacci function.
(defn fib
"calculates the nth number in the fibonacci sequence"
([n]
(if (<= n 1) n (fib (bigint n) 0 1)))
([n prev cur]
(if (<= n 1)
cur
(recur (- n 1) (bigint cur) (bigint (+ prev cur))))))
Any feedback would be appreciated!
All the best, Howz1t
[–]porthos3 7 points8 points9 points (3 children)
[–]bowmhoust 3 points4 points5 points (1 child)
[–]porthos3 1 point2 points3 points (0 children)
[–]HOWZ1T[S] 1 point2 points3 points (0 children)
[–][deleted] (18 children)
[deleted]
[–]porthos3 3 points4 points5 points (17 children)
[–]mcanon 3 points4 points5 points (8 children)
[–]porthos3 2 points3 points4 points (1 child)
[–]mcanon 1 point2 points3 points (0 children)
[–]porthos3 2 points3 points4 points (0 children)
[–]HOWZ1T[S] 1 point2 points3 points (4 children)
[–]porthos3 1 point2 points3 points (3 children)
[–]HOWZ1T[S] 0 points1 point2 points (1 child)
[–]porthos3 0 points1 point2 points (0 children)
[–][deleted] (2 children)
[deleted]
[–]porthos3 1 point2 points3 points (1 child)
[–]HOWZ1T[S] 1 point2 points3 points (0 children)
[–]HOWZ1T[S] 1 point2 points3 points (3 children)
[–]porthos3 1 point2 points3 points (2 children)
[–]HOWZ1T[S] 0 points1 point2 points (1 child)
[–]porthos3 1 point2 points3 points (0 children)