Last active
July 13, 2018 08:45
-
-
Save lugoues/1b23c5e93e3eff44729e to your computer and use it in GitHub Desktop.
Clojure: Stern-Brocot Sequence
This file contains hidden or 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
;; See: http://en.wikipedia.org/wiki/Stern%E2%80%93Brocot_tree | |
(def stern-brocot-sequence | |
(map (fn [nums] | |
(/ (first nums) (second nums))) | |
(iterate | |
(fn [nums] | |
(let [a (first nums) | |
b (second nums) | |
r (rest (rest nums))] | |
(vec (flatten (conj [] b r (+ a b) b))))) | |
[1 1]))) | |
(comment | |
(pprint (take 40 stern-brocot-sequence)) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment