Last active
March 7, 2016 21:56
-
-
Save delonnewman/90bf265abd766d413b0c to your computer and use it in GitHub Desktop.
Showing the Fibonacci Sequence approximating the Golden Ratio in WonderScript
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
(def fib | |
(memoize | |
(fn [n] | |
(cond (=== n 0) 0 | |
(=== n 1) 1 | |
:else (+ (fib (- n 1)) (fib (- n 2))))))) | |
(let [fibs (map (range 20) fib) | |
pairs (pair fibs) | |
ratios (reduce pairs (fn [memo xs] (.concat memo (apply div (.reverse xs)))) [])] | |
(each ratios | |
(fn [ratio] | |
(do | |
(println (str ratio)) | |
(println (.toNumber ratio)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment