Created
February 7, 2012 18:14
-
-
Save jrmoran/1761058 to your computer and use it in GitHub Desktop.
Fibonacci Sequence
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
(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) |
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
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