Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Generating powerset with progressive ordering

by fizbin (Chaplain)
on Feb 25, 2005 at 19:43 UTC ( #434625=note: print w/replies, xml ) Need Help??


in reply to Re: Generating powerset with progressive ordering
in thread Generating powerset with progressive ordering

Huh - so apparently your method and my evil method ended up being the same, or at least very similar. Note that you can improve this slightly by consolidating your last two expressions and eliminating the need for an "e" flag on the substitutions:
for ($str) { s/0(0*)$/1$1/ or s/1(0*)1$/01$1/ or return; }
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:
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"; }
(I've never liked do { ... } while() loops)
-- @/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/; map{y/X_/\n /;print}map{pop@$_}@/for@/

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://434625]
help
Chatterbox?
and the daffodils sway...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2017-08-21 13:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Who is your favorite scientist and why?



























    Results (323 votes). Check out past polls.

    Notices?