Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
33
Task/Pi/Raku/pi.raku
Normal file
33
Task/Pi/Raku/pi.raku
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# based on http://www.mathpropress.com/stan/bibliography/spigot.pdf
|
||||
|
||||
sub stream(&next, &safe, &prod, &cons, $z is copy, @x) {
|
||||
gather loop {
|
||||
$z = safe($z, my $y = next($z)) ??
|
||||
prod($z, take $y) !!
|
||||
cons($z, @x[$++])
|
||||
}
|
||||
}
|
||||
|
||||
sub extr([$q, $r, $s, $t], $x) {
|
||||
($q * $x + $r) div ($s * $x + $t)
|
||||
}
|
||||
|
||||
sub comp([$q,$r,$s,$t], [$u,$v,$w,$x]) {
|
||||
[$q * $u + $r * $w,
|
||||
$q * $v + $r * $x,
|
||||
$s * $u + $t * $w,
|
||||
$s * $v + $t * $x]
|
||||
}
|
||||
|
||||
my $pi :=
|
||||
stream -> $z { extr($z, 3) },
|
||||
-> $z, $n { $n == extr($z, 4) },
|
||||
-> $z, $n { comp([10, -10*$n, 0, 1], $z) },
|
||||
&comp,
|
||||
<1 0 0 1>,
|
||||
(1..*).map: { [$_, 4 * $_ + 2, 0, 2 * $_ + 1] }
|
||||
|
||||
for ^Inf -> $i {
|
||||
print $pi[$i];
|
||||
once print '.'
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue