Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^4: Generating all 5-card hands

by thor (Priest)
on May 18, 2005 at 16:34 UTC ( [id://458281]=note: print w/replies, xml ) Need Help??


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

My point is that for the purposes of this exercise, the suit doesn't matter. So, at some point, you'll end up choosing an equivalent hand to one that has already been done. For each combination of ranks, there are a fair number of equivalent hands that differ only in the suits of the individual cards. For this exercise, those hands are equivalent, so there's no point in scoring the second hand if the first hand has already been dealt with. Perhaps I mis-spoke before.

thor

Feel the white light, the light within
Be your own disciple, fan the sparks of will
For all of us waiting, your kingdom will come

Replies are listed 'Best First'.
Re^5: Generating all 5-card hands
by Limbic~Region (Chancellor) on May 18, 2005 at 16:53 UTC
    thor,
    What do you mean suit doesn't matter? In cribbage, you get 4 points if all 4 cards in your hand are the same suit. If you want to prove that no hand with a 5 isn't worth at least 2 points you HAVE to consider suits. You can easily use Re: Iterating over combinations to generate the hands. The hard part is the scoring.

    On the other hand, it is a lot easier to prove that there is a hand of 5 cards containing at least 1 five that is a total of less than 2 points.

    • 4 cards (your hand) must not all be of the same suit
    • Must not contain any cards with a value of 10
    • Must not containing any combination (excluding the 5) whose sum is 10
    • Must not contain any 2, 3, or 4 of a kind
    • Must not have any sequence of greater than 2
    I don't have an implementation yet, but it certainly does reduce the problem set.

    Cheers - L~R

      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.
        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

      I'm attempting to prove that all hands that have a five have at least two points. That's why suit doesn't matter. Suppose that I had a hand with a 5 whose only points were a flush. Now, change the suit of one of the cards. Blamo! No more points. I maintain that such a hand does not exist. I have written the program that I intended to write (I'll try to post it once I've cleaned it up a bit), and when considering the cards without considering their suit, the minimum score was two points. You're right about your bullet points though...and we've tried to use them in a more elegant "classical" proof. :)

      thor

      Feel the white light, the light within
      Be your own disciple, fan the sparks of will
      For all of us waiting, your kingdom will come

        thor,
        I am not disputing that it can be done by reducing the problem set. I was arguing that you seemed to not want to do that in your original post. Now that I have gotten out of the 3 hour long meeting it took about 3 seconds to generat a candidate list and about 1 minute to eleminate the candidates. Indeed, every hand in cribbage with a 5 has at least 2 points. See Re^7: Generating all 5-card hands for details.

        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://458281]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-03-19 08:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found