perl - How to enumerate all possible combinations of elements -
i want enumerate possible combinations of elements array. example: have array:
$r = ('a1','a2','a3' ...).
i want print combinations of element arrays: a1a2, a1a3, a1a2a3, etc . a1a2 != a2a1, a1a2a3 != a1a3a2 ...
it turns out there's a module that:
use math::combinatorics; @r = qw(a1 a2 a3 ...); #@all_combinations_of_r = map { combine($_,@r) } 1..@r; @all_permutations_of_r = map { permute(@$_) } map { combine($_,@r) } 1..@r;
Comments
Post a Comment