I've found Julia to be an excellent language for Project Euler [1]. Besides the speed, you can use Unicode identifiers, so the solution can closer follow the math.<p>1. <a href="https://projecteuler.net/" rel="nofollow">https://projecteuler.net/</a>
Nitpick: is that really computing 20M digits correctly? Reading the code gives me the impression that this does all float computations in 20 million digits (or 20 million-ish? If BigFloat internally is binary, it might use a bit more), but I would expect that you need to compute using a few more digits to avoid rounding errors in the last digits.<p>Edit: also, reading <a href="https://stackoverflow.com/a/67919533" rel="nofollow">https://stackoverflow.com/a/67919533</a>, it seems you can do<p><pre><code> BigFloat(π, precision=20000000)
</code></pre>
How does that perform?
In Wolfram Mathematica on my desktop PC with a 7 year old processor:<p><pre><code> Timing[N[\[Pi], 20000000];]
{10.1094, Null}
</code></pre>
On a fairly recent laptop CPU I got 7.6 seconds.<p>A fair ways to go still!
This is pretty cool. One minor gripe is that there were a lot of useless type asserts cluttering things up. every usage of ::BigFloat here wasn't needed.
Just wanted to mention that SuperPi - the benchmark that is very widely used for at least a decade for measuring PC / CPU single threaded performance uses the same algorithm so not really obscure.
That said, multi threaded algorithms make more sense for modern multi core computer architectures, something like this for example:<p><a href="http://www.numberworld.org/y-cruncher/" rel="nofollow">http://www.numberworld.org/y-cruncher/</a>
For reference: <a href="https://en.wikipedia.org/wiki/Gauss%E2%80%93Legendre_quadrature" rel="nofollow">https://en.wikipedia.org/wiki/Gauss%E2%80%93Legendre_quadrat...</a>
Here is a video [1] and associated java source code [2] from pi day in 2018 to generate 1M (or more) digits of pi using the same Gauss-Legendre algorithm.<p>[1] <a href="https://www.youtube.com/watch?v=8RONJPOgZjw">https://www.youtube.com/watch?v=8RONJPOgZjw</a><p>[2] <a href="https://github.com/R-e-t-u-r-n-N-u-l-l/Java-Algorithms/blob/master/ApproxPi.java">https://github.com/R-e-t-u-r-n-N-u-l-l/Java-Algorithms/blob/...</a>
Isn't this is more hardware dependent? A 2012 Intel notebook vs a 2022 AMD laptop would yield different results with same code. Also a well tune assembly can do these way faster. A python wrapped with assembly functions and run on a machine 6ghz Intel machine with ramdisk would also outperform this. I always feel this kind of claim is not helpful in day to day usage.