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;
}
|