Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

•Re: Re: •Re: Puzzle: need a more general algorithm

by merlyn (Sage)
on Jul 12, 2002 at 19:39 UTC ( #181383=note: print w/ replies, xml ) Need Help??


in reply to Re: •Re: Puzzle: need a more general algorithm
in thread Puzzle: need a more general algorithm

As we discussed in that meeting, here's the code snippet I was thinking about to generate the binary strings:

print map "$_\n", strings_for(6, 4); sub strings_for { my ($cats, $cols) = @_; $cats--; $cols--; my @ret; for (0..(1 << $cats) - 1) { my $bitstring = substr(unpack("B*", pack "N", $_), -$cats); next unless $bitstring =~ tr/1// == $cols; push @ret, $bitstring; } @ret; }

-- Randal L. Schwartz, Perl hacker


Comment on •Re: Re: •Re: Puzzle: need a more general algorithm
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://181383]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2015-07-05 18:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (67 votes), past polls