sub weird(@elems, :$direction = 'forward') {
my %direction = (
forward => sub { take $_ for @elems },
backward => sub { take $_ for @elems.reverse },
random => sub { take $_ for @elems.pick(*) },
);
return gather %direction{$direction}();
}
say weird(<a b c>, :direction<backward> );
my @vals = lazy gather {
for ^Inf {
take $_ if .is-prime;
}
}
say @vals[10000];
say now - INIT now;
my $n = 20;
my @a = gather for 1..$n -> $x {
for $x..$n -> $y {
for $y..$n -> $z {
take $x,$y,$z if $x² + $y² == $z²;
}
}
};
.say for @a;
my @a = 1..20;
my @c = gather for @a.combinations(3)».permutations {
take .[0], .[1], .[2] if .[0]² + .[1]² == .[2]² for .Array;
}
say @c;