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;
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.