Last active
June 15, 2017 15:08
-
-
Save oliverjam/efdcdac20653d17f4f0516fc1d16acdb to your computer and use it in GitHub Desktop.
null created by oliverjam - https://repl.it/InIk/0
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
function calculatePi(dp = 200000) { | |
let pi = 3; | |
let i = 2; | |
while (i < dp) { | |
const divisor = 4 / (i * (i + 1) * (i + 2)); | |
if (i % 4 === 0) { | |
pi -= divisor; | |
} else { | |
pi += divisor; | |
console.log(i + ' ' + pi); | |
} | |
i += 2; | |
} | |
return pi; | |
} | |
calculatePi(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment