We don't bite newbies here... much PerlMonks

### Comment on

 Need Help??
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)
[download]```
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;
}
[download]```

Cheers - L~R

In reply to Re^7: Generating all 5-card hands by Limbic~Region
in thread Generating all 5-card hands by thor

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• Please read these before you post! —
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?
• See Writeup Formatting Tips and other pages linked from there for more info.
• Log In?
 Username: Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (10)
As of 2018-11-21 17:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
My code is most likely broken because:

Results (245 votes). Check out past polls.

Notices?