I don't know why, but this problem intrigued me.
This problem is very similiar to counting the number of partitions for the number 21, which is quite simple.
But there are several factors which makes this a much more complicated problem, and make it almost impossible to
exhaustively list and count every possibility (at least by hand, that is):
1) An ace can count for one point or eleven points.
2) There are 4 suits of cards, so there are 4 2's, 4 3's, 4 aces, etc.
3) Within each suit, 4 cards (10, Jack, Queen, King) have identical value (10 points).
One way to try to count all the possibilites is to first count the number of possibilities which use only two cards,
then count the number which use exactly 3 cards, and so on. The problem with this method, as Dr. Pizza has shown,
is that the number of possibilities grows rather unwiedly as you increase the number of cards to use.
Instead, we should try to expoit some of the symetries of the problem, and break the problem down into two smaller, but related problems:
1) For each number 0 through 21, find out how many possible
card combinations from a single suit of cards add up to that number.
and
2) Find all possible ways to split 21 points amongst the four suits.
How does this help? We are basically categorizing each possible card combination that sums to 21 by the sum of the cards within each suit. By counting the number of possible card combinations in each of these categories, and then summing this over all of the categories we will have our final answer. Problem #1 will tell us how many combinations are in a specific category, while Problem #2 will give us a list of each category.
We start with Problem #1: for each number 0 through 21, how many possible card combinations from a single suit of cards add up that number? For each number n from 0 through 21, let's call this number P(n).
For simplicity in counting, let's label each card combination (hand) with a number, where each digit represents a card's value, by ordering the cards from highest to lowest in value. I use a '1' to designate an ace being used as a one, an 'A' to designate an ace with a point value of 11, and 'T' to designate any one of the four cards (ten,jack,queen, king) with a point-value of 10.
Hence, the card combination labeled "A53" represents an ace (with value 11), a 5, and a 3, all of one suit. This hand totals 19.
Now the question is, how many combinations of a single suit add up to 0? Obviously, only a hand with no cards-- so just one possibility. So P(0) = 1.
How many combinations add up to 1? Only the hand "1" (i.e. the ace being used as a one), so the answer is also 1. So P(1) = 1.
How many add up to 2? Only the hand "2" does, so the answer is again 1. So P(2) = 1.
How many add up to 3? There are two: "3" and "21". So P(3) = 2.
How many add up to 4? There are two: "4", and "31". Note we cannot use "22" as there is only one 2 card in the suit. So P(4)= 4.
For 5, there are 3 hands ("5", "41", and "32"). For 6, there are 4 hands ("6", "51", "42", and "321").
Using the greedy algorithm, it is a relatively trivial process to list and count all hands of a single suit that sums to a particular number from 0 through 21. You can even re-use some of your early work later on, as listing all of the one-suit hands that total to 18 with a largest card value of 7 is equivalent to listing all hands that total to 11 with a largest card value less than 7. Just remember to not count any hand that has an ace being used as both a one and an eleven, any hand labeled with a single "T" actually represents 4 hands, and any hand label with two "T"'s actually represents 4 * 3 / 2 = 6 hands (since each T can actually be a ten, jack, queen, or king).
We find that P(7) = 5, P(8) = 6, P(9) = 8, P(10) = 13, P(11) = 15, P(12) = 16, P(13) = 22, P(14) = 24, P(15) = 30, P(16) = 36, P(17) = 41, P(18) = 48, P(19) = 56, P(20) = 69, and P(21) = 77.
Now for Problem #2-- list each distinct way to split 21 points among the 4 suits. This is also relatively easy to do using the greedy algorithm.
For simplicity, we group each possible way by ordering the point totals from each suit from highest to lowest, which is then used to label the group. Hence the label is irrespective of the actual suits used.
For instance, one possible way is for all of the hearts to total 12, all of the diamonds to total 6, all of the clubs to total 2, and all of the spades to total 1. We label this category "12,6,2,1". Note that, another possible way is for all of the diamonds to total 12, all of the spades to total 6, all of the hearts to total 2, and all of the clubs to total 1. This way would also be labeled "12,6,2,1"-- in fact, any way in which one hand totals 12, another totals 6, another 2, and the remaning hand totals 1 would be so labeled. Hence the label "12,6,2,1" actually represents 4 * 3 * 2 * 1 = 24 distinct ways or categories.
Similiarily, the label "15,5,5,1" actually represents 4 * 3 * 2 * 1 / 2 = 12 distinct ways or categories.
The label "12,3,3,3" actually represents 4 * 3 * 2 * 1 / ( 3 * 2 * 1) = 4 distinct ways or categories.
It turns out there are 118 groups. The obvious group
"21,0,0,0" represents all categories in which 21 points come from a single suit, and 0 points come from each of the other 3. There are 4 such categories. From Problem #1 above, we know for a single suit there are P(21), or
77, ways for cards of that suit to total 21, and P(0) = 1 way for cards to total 0. Hence, the group "21,0,0,0" represents 4 * 77 * 1 * 1 * 1 = 308 distinct card hands that total 21.
The next group is
"20,1,0,0" and represents all categories in which 20 points come from a single suit, 1 point comes from a second suit, and 0 points come from the other 2. There are 12 such categories. From Problem #1, we know for a single suit there are P(20) = 69 ways for cards of that suit to total 20, P(1) = 1 way for cards to total 1, and P(0) = 1 way for cards to total 0. Hence, the group "20,1,0,0" represents 12 * 69 * 1 * 1 * 1 = 828 distinct card hands that total 21.
A list of all groups, the number of categories it represents, and the total number of distinct card hands that total 21 in that group follow in the code section below. Summing that all up, we have our answer.
Cliffs:
There are 187,332 distinct card combinations that total 21... unless I made a mistake somewhere, which is quite likely.
EDIT: The code box is stripping the carriage returns, so I'll list the 118 groupings of 21-point distributions amongst the 4 suits below. Next to each grouping is how many different suit combinations are represented in the group, and then how many total card hands fall into that group.
EDIT 2: Added two more groupings I initially missed. The total is the latest and greatest.
{21,0,0,0} 4 308
{20,1,0,0} 12 828
{19,2,0,0} 12 672
{19,1,1,0} 12 672
{18,3,0,0} 12 1,152
{18,2,1,0} 24 1,152
{18,1,1,1} 4 192
{17,4,0,0} 12 984
{17,3,1,0} 24 1,968
{17,2,2,0} 12 492
{17,2,1,1} 12 492
{16,5,0,0} 12 1,296
{16,4,1,0} 24 1,728
{16,3,2,0} 24 1,728
{16,3,1,1} 12 864
{16,2,2,1} 12 432
{15,6,0,0} 12 1,440
{15,5,1,0} 24 2,160
{15,4,2,0} 24 1,440
{15,4,1,1} 12 720
{15,3,3,0} 12 1,440
{15,3,2,1} 24 1,440
{15,2,2,2} 4 120
{14,7,0,0} 12 1,440
{14,6,1,0} 24 2,304
{14,5,2,0} 24 1,728
{14,5,1,1} 12 864
{14,4,3,0} 24 2,304
{14,4,2,1} 24 1,152
{14,3,3,1} 12 1,152
{14,3,2,2} 12 576
{13,8,0,0} 12 1,584
{13,7,1,0} 24 2,640
{13,6,2,0} 24 2,112
{13,6,1,1} 12 1,056
{13,5,3,0} 24 3,168
{13,5,2,1} 24 1,584
{13,4,4,0} 12 1,056
{13,4,3,1} 24 2,112
{13,4,2,2} 12 528
{13,3,3,2} 12 1,056
{12,9,0,0} 12 1,536
{12,8,1,0} 24 2,304
{12,7,2,0} 24 1,920
{12,7,1,1} 12 960
{12,6,3,0} 24 3,072
{12,6,2,1} 24 1,536
{12,5,4,0} 24 2,304
{12,5,3,1} 24 2,304
{12,5,2,2} 12 576
{12,4,4,1} 12 768
{12,4,3,2} 24 1,536
{12,3,3,3} 4 512
{11,10,0,0} 12 2,340
{11,9,1,0} 24 2,880
{11,8,2,0} 24 2,160
{11,8,1,1} 12 1,080
{11,7,3,0} 24 3,600
{11,7,2,1} 24 1,800
{11,6,4,0} 24 2,880
{11,6,3,1} 24 2,880
{11,6,2,2} 12 720
{11,5,5,0} 12 1,620
{11,5,4,1} 24 2,160
{11,5,3,2} 24 2,160
{11,4,4,2} 12 720
{11,4,3,3} 12 1,440
{10,10,1,0} 12 2,028
{10,9,2,0} 24 2,496
{10,9,1,1} 12 1,248
{10,8,3,0} 24 3,744
{10,8,2,1} 24 1,872
{10,7,4,0} 24 3,120
{10,7,3,1} 24 3,120
{10,7,2,2} 12 780
{10,6,5,0} 24 3,744
{10,6,4,1} 24 2,496
{10,6,3,2} 24 2,496
{10,5,5,1} 12 1,404
{10,5,4,2} 24 1,872
{10,5,3,3} 12 1,872
{10,4,4,3} 12 1,248
{9,9,3,0} 12 1,536
{9,9,2,1} 12 768
{9,8,4,0} 24 2,304
{9,8,3,1} 24 2,304
{9,8,2,2} 12 576
{9,7,5,0} 24 2,880
{9,7,4,1} 24 1,920
{9,7,3,2} 24 1,920
{9,6,6,0} 12 1,536
{9,6,5,1} 24 2,304
{9,6,4,2} 24 1,536
{9,6,3,3} 12 1,536
{9,5,5,2} 12 864
{9,5,4,3} 24 2,304
{9,4,4,4} 4 256
{8,8,5,0} 12 1,296
{8,8,4,1} 12 864
{8,8,3,2} 12 864
{8,7,6,0} 24 2,880
{8,7,5,1} 24 2,160
{8,7,4,2} 24 1,440
{8,7,3,3} 12 1,440
{8,6,6,1} 12 1,152
{8,6,5,2} 24 1,728
{8,6,4,3} 24 2,304
{8,5,5,3} 12 1,296
{8,5,4,4} 12 864
{7,7,7,0} 4 500
{7,7,6,1} 12 1,200
{7,7,5,2} 12 900
{7,7,4,3} 12 1,200
{7,6,6,2} 12 960
{7,6,5,3} 24 2,880
{7,6,4,4} 12 960
{7,5,5,4} 12 1,080
{6,6,6,3} 4 512
{6,6,5,4} 12 1,152
{6,5,5,5} 4 432
--------
TOTAL: 188,052