Skip to content

Instantly share code, notes, and snippets.

@divs1210
Last active July 29, 2018 04:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save divs1210/b2076eeaf533d5e49262bd9684381b9a to your computer and use it in GitHub Desktop.
Save divs1210/b2076eeaf533d5e49262bd9684381b9a to your computer and use it in GitHub Desktop.
Clojure ratios
;; clojure solution for https://medium.com/@bellmar/is-cobol-holding-you-hostage-with-math-5498c0eb428b
;; HN: https://news.ycombinator.com/item?id=17636029
(defn rec [y z]
(- 108
(/ (- 815
(/ 1500 z))
y)))
(defn rec-list [N]
(->> (iterate (fn [[x:i-2 x:i-1]]
[x:i-1 (rec x:i-1 x:i-2)])
[4 17/4])
(take N)
(map first)
(map double)))
;; Usage
;; =====
(rec-list 20)
;; returns
(4.0
4.25
4.470588235294118
4.644736842105263
4.770538243626062
4.855700712589074
4.910847499082793
4.945537404123917
4.966962581762701
4.980045701355631
4.987979448478392
4.992770288062068
4.995655891506634
4.997391268381344
4.998433943944817
4.999060071970894
4.999435937146839
4.999661524103768
4.999796900713418
4.999878135477931)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment