http://www.perlmonks.org?node_id=458293

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

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

Replies are listed 'Best First'.
Re^6: Generating all 5-card hands
by Roy Johnson (Monsignor) on May 18, 2005 at 17:58 UTC
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

Re^6: Generating all 5-card hands
by thor (Priest) on May 18, 2005 at 18:26 UTC
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