Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^6: Generating all 5-card hands

by Roy Johnson (Monsignor)
on May 18, 2005 at 17:58 UTC ( [id://458354]=note: print w/replies, xml ) Need Help??


in reply to Re^5: Generating all 5-card hands
in thread Generating all 5-card hands

If you want to prove that no hand with a 5 isn't worth at least 2 points you HAVE to consider suits.
Why? You aren't interested in the case where they are the same suit. You just assume that they're not all the same suit; which suits they are is immaterial.

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^7: Generating all 5-card hands
by Limbic~Region (Chancellor) on May 18, 2005 at 20:34 UTC
    Roy Johnson,
    Because (but not really). To quote thor:

    What I want to do is write a program that brute forces the issue. That is to say that I want to create a program that scores all 5-card hands that have a 5 in them and see what happens.

    Eliminating suits doesn't meet the original requirements. That isn't to say there is anything wrong with appending or updating or clariffying the original requirements. I was just saying that if you want all then you need all. I did go on to say it is possible to prove it by starting out conceptually with all the known impossible solutions removed and only testing the remainder.

    Incidently, believe the brute force part is easy. Start by selecting 4 card hands (5 is assumed) from 1..4, 6..9 where no combination adds up to 10:

    1 3 4 8 - BAD (3,4,5) 1 4 7 8 - BAD (7 + 8 = 15) 1 6 7 8 - BAD (7 + 8 = 15) 2 3 4 9 - BAD (9 + 4 + 2 = 15) 2 3 6 9 - BAD (9 + 6 = 15) 2 4 7 9 - BAD (9 + 4 + 2 = 15) 2 6 7 9 - BAD (9 + 6 = 15) 3 4 8 9 - BAD (3,5,5) 3 6 8 9 - BAD (9 + 6 = 15) 4 7 8 9 - BAD (7 + 8 = 15) 6 7 8 9 - BAD (9 + 6 = 15)
    I used the following code (see this for combo sub):
    #!/usr/bin/perl use strict; use warnings; # Assume that all my $iter = combo( 4, 1..4, 6..9 ); while ( my @combo = $iter->() ) { next if make_10( @combo ); print "@combo\n"; } sub make_10 { my @hand = @_; for ( 2 .. 4 ) { my $iter = combo( $_, @hand ); while ( my @combo = $iter->() ) { my $tot = 0; $tot += $_ for @combo; return 1 if $tot == 10; } } return 0; }

    Cheers - L~R

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-19 19:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found