組み合わせの取得
Math::Combinatoricsモジュールを使うと組み合わせ(nCk)を取得できます。
use strict; use warnings; use Math::Combinatorics; my @items = qw(a b c d); # 4つから3つを取り出す組み合わせ my @combine = combine(3, @items); foreach my $c (@combine) { print join(" ", @$c), "\n"; }
use strict; use warnings; use Math::Combinatorics; my @items = qw(a b c d); # 4つから3つを取り出す組み合わせ my @combine = combine(3, @items); foreach my $c (@combine) { print join(" ", @$c), "\n"; }