>

$\mathrm{with}\left(\mathrm{Iterator}\right)\:$

Construct an iterator corresponding to the number of ways to choose 5 balls from a bucket with 2 red balls, 5 green balls, and 3 black balls.
>

$B\u2254\mathrm{MultiCombination}\left(\left[2\,5\,3\right]\,5\right)\:$

Print each combination. The 1s correspond to red balls, the 2s to green balls, and the 3s to black balls.
>

$\mathbf{for}\phantom{\rule[0.0ex]{0.3em}{0.0ex}}b\phantom{\rule[0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[0.0ex]{0.3em}{0.0ex}}B\phantom{\rule[0.0ex]{0.3em}{0.0ex}}\mathbf{do}\phantom{\rule[0.0ex]{0.0em}{0.0ex}}\phantom{\rule[0.0ex]{2.0em}{0.0ex}}\mathrm{printf}\left(''\%d\backslash n''\,b\right)\phantom{\rule[0.0ex]{0.0em}{0.0ex}}\mathbf{end}\phantom{\rule[0.0ex]{0.3em}{0.0ex}}\mathbf{do}\:$

1 1 2 2 2
1 2 2 2 2
2 2 2 2 2
1 1 2 2 3
1 2 2 2 3
2 2 2 2 3
1 1 2 3 3
1 2 2 3 3
2 2 2 3 3
1 1 3 3 3
1 2 3 3 3
2 2 3 3 3
 
Compute the number of ways to select four entrees from a menu of 10 dishes allowing multiple selections of any of the entrees. Because four is the most that can be selected, this is equivalent to assigning four as the multiplicity of all items.
>

${\mathrm{Number}\left(\mathrm{MultiCombination}\left(\left[\mathrm{`\$`}\left(4\,10\right)\right]\,4\right)\right)}}$

Suppose one is allowed to choose any entree no more than twice. This can be expressed as
>

${M\u2254\mathrm{MultiCombination}\left(\left[\mathrm{`\$`}\left(2\,10\right)\right]\,4\right)\:}}$

There are 615 ways to obtain such a combination.
>

$\mathrm{Number}\left(M\right)$


Number of Distinct Ranks of a Poker Hand


•

A standard poker hand consists of five cards drawn from a 52 card deck, with four suits of 13 cards per suit.

•

The rank of a hand depends first on its category (straight flush, four of a kind, etc.), then on its rank within that category. The rank does not depend on the suits, with the exception that a flush (all five cards of the same suit) is a separate category.

•

The number of distinct hand ranks equals the number of possible flushes of a given suit plus the number of multicombinations of five cards from a deck with four cards of each rank.

•

The number of possible flushes of a given suit is simply the number of ways to choose a set of five objects from a set of thirteen distinct objects. The binomial function computes the result, $\left(\genfrac{}{}{0ex}{}{13}{5}\right)$. It can also be computed using the Number method of the Combination object:

>

$\mathrm{numF}\u2254\mathrm{Number}\left(\mathrm{Combination}\left(13\,5\right)\right)$

${\mathrm{numF}}{\u2254}{1287}$
 (3) 
•

Construct an iterator that generates each of the multcombinations of five cards drawn from a deck.

>

${H\u2254\mathrm{MultiCombination}\left(\left[\mathrm{`\$`}\left(4\,13\right)\right]\,5\right)\:}}$

•

Count the number of multicombinations. We can do this in a number of ways; one is simply to invoke the Number method.

>

$\mathrm{numH}\u2254\mathrm{Number}\left(H\right)$

${\mathrm{numH}}{\u2254}{6175}$
 (4) 
•

For this case, it is also practical to count the iterations one by one.

>

$\mathrm{numH}\u2254\mathrm{add}\left(1\,h=H\right)$

${\mathrm{numH}}{\u2254}{6175}$
 (5) 
•

A final method is the following. If there were five of each ranked card, rather than four, we would obtain exactly 13 more distinct ranked hands then the actual deck (the 13 five of a kind). This is expressed by the following formula:

>

${\mathrm{numH}\u2254\mathrm{Number}\left(\mathrm{MultiCombination}\left(\left[\mathrm{`\$`}\left(5\,13\right)\right]\,5\right)\right)13}}$

${\mathrm{numH}}{\u2254}{6175}$
 (6) 
•

The total number of distinct ranks of poker hands is

>

$\mathrm{numF}+\mathrm{numH}$

