Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Generating all 5-card hands

by Roy Johnson (Monsignor)
on May 18, 2005 at 14:54 UTC ( #458235=note: print w/ replies, xml ) Need Help??


in reply to Generating all 5-card hands

The set of all five-card hands with a 5 is the set of all four-card hands in a deck missing a 5, plus a 5-card. The easy way would be to use glob:

print "$_\n" while $_=glob '5,{A,2,3,4,6,7,8,9,10,J,Q,K}' .',{A,2,3,4,5,6,7,8,9,10,J,Q,K}'x3;
but it's not a truly iterative solution (it generates the whole set before beginning iteration). Consider Algorithm::Loops, or Iterating over combinations (found by Super Searching on combinations and iterator).

Caution: Contents may have been coded under pressure.


Comment on Re: Generating all 5-card hands
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2015-07-04 08:55 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 (58 votes), past polls