Skip to content

Instantly share code, notes, and snippets.

@Tubbz-alt
Forked from jrmoran/fibonacci-50.clj
Created May 28, 2021 15:19
Show Gist options
  • Select an option

  • Save Tubbz-alt/27953abf3ca5bc08847546ce8f7d82e0 to your computer and use it in GitHub Desktop.

Select an option

Save Tubbz-alt/27953abf3ca5bc08847546ce8f7d82e0 to your computer and use it in GitHub Desktop.
Fibonacci Sequence
(defn fib [n]
(Math/round (/ (- (Math/pow 1.618034 n)
(Math/pow (- 0.618034) n))
(Math/sqrt 5))))
(map fib (range 51))
;; (0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 2178309 3524579 5702888 9227467 14930356 24157823 39088179 63246003 102334183 165580188 267914374 433494567 701408948 1134903525 1836312490 2971216044 4807528580 7778744699 12586273401)
var fib_accumulator = function(a, b, limit){
console.log(a);
return limit === 0 ? b : fib_accumulator(b, a + b, --limit);
};
fib_accumulator(0, 1, 49);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment