P26 - 从列表的 n 个元素中生成 k 个不同对象的组合。
作者:Ryan Connelly
示例
> say c(2, <a b c d e>); ((a b) (a c) (a d) (a e) (b c) (b d) (b e) (c d) (c e) (d e))
源代码: P26-topo.pl
use v6; multi sub c(0, @xs) { return ((),) } multi sub c(Int $n, []) { return () } multi sub c(Int $n, [ $x, *@xs ]) { |map({($x, |@$_)}, c($n - 1, @xs)), |c($n, @xs); } my @combos = c(3, <a b c d e f g h i j k l>); say @combos.elems; say @combos[200..*];