Skip to content

Instantly share code, notes, and snippets.

@lagenorhynque
Last active October 1, 2017 13:01
Show Gist options
  • Select an option

  • Save lagenorhynque/6bae59021418fbc96c7d757f93bf1a32 to your computer and use it in GitHub Desktop.

Select an option

Save lagenorhynque/6bae59021418fbc96c7d757f93bf1a32 to your computer and use it in GitHub Desktop.
;; cf. https://en.wikipedia.org/wiki/Leibniz_formula_for_%CF%80
user> (require '[clojure.math.numeric-tower :as math])
nil
user> (def leibniz (map / (iterate - 4) (iterate #(+ % 2) 1)))
#'user/leibniz
user> (->> leibniz
(take-while #(> (math/abs %) 1/1000))
(apply +)
double)
3.141092653621043
user>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment