Created
September 8, 2017 22:14
-
-
Save JoeCooper/ae953a1ffe48a20f29b1450ad30fef67 to your computer and use it in GitHub Desktop.
Leibniz formula for π in Scheme. As iteration count approaches infinity, result approaches π.
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
| (define (leibnizFormulaForPi steps) | |
| (define (stage step) (* (/ 1 (+ 1 (* step 2))) (if (= (modulo step 2) 1) -1 1))) | |
| (define (iterate thusFar step steps) | |
| (if (< step steps) | |
| (iterate (+ thusFar (stage step)) (+ step 1) steps) | |
| (+ thusFar (stage step)) | |
| ) | |
| ) | |
| (* 4 (iterate 0 0 steps)) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment