P15 - 将列表中的元素复制指定次数。
作者:David Romano
规范
P15 (**) Replicate the elements of a list a given number of times.
示例
> say prob15(<a b c>, 3); a a a b b b c c c
源代码:P15-unobe.pl
use v6;
my @l = <a b c>;
sub prob15(@in, $n) {
gather { for 0 ... @in.end -> $i { for 1 ... $n { take @in[$i] } } }
}
say @l.perl;
say prob15(@l, 3).list.perl;
Perl 6 示例