The nice book of Andrew Shitov: Raku one-liners

In a chapter of the book, the author demonstrates a (slow) computation of Pi decimals. But using BBP formula, a better, and more amazing solution may be build, at the price of slightly a longer line.

BBP formula in one line (map version)

With the following code, only 12 sums are sufficient to arrive at the limit of the standard value of pi in Raku, as standard Rat use standard int.

raku -e 'say pi - [+] (^12).map( {(1/(16**$_))*(4/(8*$_ +1) - 2/(8*$_+4) - 1/(8*$_+5) - 1/(8*$_+6))} )'

Too many decimals

But with FatRat, you can achieve arbitrary accuracy !

raku -e 'say [+] (^100).map( {FatRat.new(1,16**$_)*( FatRat.new(4,8*$_ +1) - FatRat.new(2,8*$_+4) - FatRat.new(1,8*$_+5) - FatRat.new(1,8*$_+6))} )'