For those of us behind work proxies that dumbly think this site is "domain parking" or worse: http://archive.is/hUo6Q
A Million Digits of Pi in 9 Lines of JavaScript
61–70 of 86 posts
Re: A Million Digits of Pi in 9 Lines of JavaScript
#62Re: A Million Digits of Pi in 9 Lines of JavaScript
#63I thought it would be the "spigot" algorithm, which is based on Bellard's formula (yes, that Bellard) and yields similarly small programs: http://numbers.computation.free.fr/Constants/TinyPrograms/ti...
Re: A Million Digits of Pi in 9 Lines of JavaScript
#64Got you beat, js.
Re: A Million Digits of Pi in 9 Lines of JavaScript
#65His demo page, in my Chrome, if I enter 10000, it takes about 2 seconds to finish with 10k digits. But if I enter 100k, it takes 30 seconds to get to reporting 10k digits worth of progress. Hmm. Have to think about that one. Just cause it's asking JS to do comparisons of much larger numbers?
It's not just the comparisons, it's the additions, multiplications and divisions too. When you enter 10,000, each iteration of the loop is working with numbers 10,000 digits long. When you enter 100,000, each iteration is working with numbers 100,000 digits long, which I imagine makes every operation slower.
Re: A Million Digits of Pi in 9 Lines of JavaScript
#66Re: A Million Digits of Pi in 9 Lines of JavaScript
#67JS Error `No identifiers allowed directly after numeric literal` when running http://ajennings.net/pi.html on Mac OS Mojave 10.14.6, Safari 12.1.2 (14607.3.9)
Re: A Million Digits of Pi in 9 Lines of JavaScript
#68let y=3n*(10n**1000020n); const f=(i,x,p)=>{(x>0)?f(i+2n,x*i/((i+1n)*4n),p+x/(i+2n)):p/(10n**20n)} console.log(f(1n,y/8n,y)); Not sure if I can golf it anymore
Re: A Million Digits of Pi in 9 Lines of JavaScript
#69let y=3n*(10n**1000020n); const f=(i,x,p)=>{(x>0)?f(i+2n,x*i/((i+1n)*4n),p+x/(i+2n)):p/(10n**20n)} console.log(f(1n,y/8n,y)); Not sure if I can golf it anymore
That version already doesn’t work… once you fix the arrow function, there’s also the issue that most engines today don’t support proper tail calls, so nothing recursive will be portable. (But if it did, you could save a lot of characters by dropping unnecessary parentheses, expanding (i+1n)×4n to 4n×i+4n, replacing the const with a comma, removing semicolons…)
map$l+=(-1)$_/(1-$_2)4,1..;die$l
Re: A Million Digits of Pi in 9 Lines of JavaScript
#70Earlier quoted context omitted.
That version already doesn’t work… once you fix the arrow function, there’s also the issue that most engines today don’t support proper tail calls, so nothing recursive will be portable. (But if it did, you could save a lot of characters by dropping unnecessary parentheses, expanding (i+1n)×4n to 4n×i+4n, replacing the const with a comma, removing semicolons…)
this is my perl golf version of the same series. You can probably can do something similar with js: map$l+=(-1) $_/(1-$_ 2) 4,1.. ;die$l
[0]: https://tio.run/##K0gtyjH9/z83sUAlR9tWQ9dQUyVeX8NQVyXeSNNEx1...