This code:
sub MAIN(Int $N = 128)
{
my @pascal = ((1,), { (0, |@^a) Z+ (|@^a, 0) } ... *);
my @top = @pascal[^$N];
say "Percentage of odd numbers in the first $N rows: ",
(100 × @top».grep(* % 2).sum / @top.sum).fmt('%.12f%%');
}
gives me an error:
The iterator of this Seq is already in use/consumed by another Seq
(you might solve this by adding .cache on usages of the Seq, or
by assigning the Seq into an array)
in sub MAIN at ./pascal1 line 8
in block <unit> at ./pascal1 line 1
Any idea how to solve it? I've tried adding .cache
in several places, but no luck.