in reply to Re: Generating powerset with progressive ordering
in thread Generating powerset with progressive ordering
And actually, we can combine your method and the last bit in my post to get this somewhat natural structure for looping through the possibilities:for ($str) { s/0(0*)$/1$1/ or s/1(0*)1$/01$1/ or return; }
(I've never liked do { ... } while() loops)sub nextmask { if ($_[0] =~ s/0(0*)$/1$1/) {1;} elsif ($_[0] =~ s/1(0*)1$/01$1/) {2;} else {0;} } my @factors = qw(2 3 5 7); my $mask = '0' x scalar(@factors); while (my $transtype = nextmask($mask)) { print "BREAK\n" if ($transtype > 1); # do stuff print join " ", map { substr($mask, $_, 1) ? $factors[$_] : ' ' } 0 .. $#factors; print "\n"; }
-- @/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/; map{y/X_/\n /;print}map{pop@$_}@/for@/
|
---|