my @x = qw(a b c d e f); my $n = 4; my $x = (1<<$n)-1; while( $x < 1<<@x ){ my $i = $x<<1; print join", ",(grep{($i>>=1)&1}@x),"\n"; $i = $x&(~$x>>1); $i &= -$i; $x += $i--; if( $i &= $x ){ $x -= $i; $i /= ($i&-$i); $x += $i; } }
In reply to Re: How do I get all n element subsets of an array
by I0
in thread How do I get all n element subsets of an array
by NodeReaper
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |