[Math] How many different ways are there to get a 21 in Black Jack

card-gamescombinationspermutations

Using one deck of cards.

Taking into account different suites. However, the way they are arranged would not be accounted for. Ace of Spades and Queen of Diamonds would be the same as Queen of Diamonds and Ace of Spades.

Pictures (Jacks, Queens, Kings) = 10

Aces = 11, or 1

The way I see it, 21 can be split into:

20 + 1, 19 + 2, 18 + 3 … 1 + 20. Each of those numbers can further be split down. It appears to be kind of recursive?

Then we have 2-card ways, 3-card ways, 4-card ways and so on …

It seems to me a very, very tough problem and I have no idea how to approach it. Any ideas?

Best Answer

This Python code by @niemmi on Stack Overflow says that there are 186,184 ways.

import operator
from math import factorial

def bcoef(n, k):
    return factorial(n) / (factorial(k) * factorial(n - k))

def combinations(limit, start, used):
    if limit == 0:
        # For each face value figure out how many combinations can be used
        combs = (bcoef(4 if i != 10 else 16, x) for i, x in enumerate(used))
        res = reduce(operator.mul, combs, 1)
        return res

    res = 0
    for i in range(start, 12):
        if i > limit:
            break

        index = i if i != 11 else 1

        if used[index] < 4:
            used[index] += 1
            res += combinations(limit - i, i, used)
            used[index] -= 1

    return res

print combinations(21, 1, [0] * 11) # 186184