Last active
August 29, 2015 14:14
-
-
Save keyvanakbary/1b9eb63d5f95afd81713 to your computer and use it in GitHub Desktop.
Nilakantha's series for calculating π
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
(defn nilakantha [iterations] | |
(loop [sum 3.0M | |
counter 0 | |
sign +] | |
(if (>= counter (* 2 iterations)) | |
sum | |
(recur | |
(sign sum | |
(/ 4.0M | |
(* (+ counter 2) | |
(+ counter 3) | |
(+ counter 4)))) | |
(+ counter 2) | |
(if (= sign +) - +))))) | |
(println | |
(with-precision 10000 | |
(nilakantha 150))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment