Skip to content

Instantly share code, notes, and snippets.

@delonnewman
Last active March 7, 2016 21:56
Show Gist options
  • Save delonnewman/90bf265abd766d413b0c to your computer and use it in GitHub Desktop.
Save delonnewman/90bf265abd766d413b0c to your computer and use it in GitHub Desktop.
Showing the Fibonacci Sequence approximating the Golden Ratio in WonderScript
(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