I used the following die: d4, d6, d8, d10, d12, and d20. Each iteration, I start at 2 die and work my way up to 20 die. For each number set of die, I roll them 20,000 times.

int roll(std::vector<int> die, int faces) {
int score = 0;
int total = 0;
int size = die.size();
int i = 0;
while (i < size) {
total += RNG(faces);
i++;
};
if (total == 21) {
score = 1;
};
return score;
};

int main() {

int i = 0;
int numDie = 2;
int faces = 4;
int score = 0;
std::vector<int> die;
std::vector<int> scores;
srand(time(NULL));

bullshit to hide from repliesbullshit to hide from repliesbullshit to hide from repliesbullshit to hide from repliesbullshit to hide from repliesbullshit to hide from repliesbullshit to hide from repliesbullshit to hide from repliesbullshit to hide from repliesbullshit to hide from repliesbullshit to hide from repliesbullshit to hide from repliesbullshit to hide from repliesbullshit to hide from repliesbullshit to hide from repliesbullshit to hide from replies

I'll do some of the same analysis that Ghowilo did later, but for now a couple of easy observations:

*If you have n dice with d faces, you can get every possible value from n to nd.

*To get to 21, you need enough dice to add up to that amount. So nd has to be at least 21. For instance, you need at least 6 D4 to have a chance of getting 21.

*The most dice you could use is 21, since any more than that and you're guaranteed to get at least 22 points.

Each list shows, for the minimum n up to the maximum of 21, what the probability of rolling a 21 is after 10000 trials. The best seems to be rolling 8 4-sided dice.

So, here's some intuition. Think about rolling two D6. You can hit every value between 2 and 12, and the distribution is symmetric about the mean of (2 + 12)/2 = 7.

The average value of the range is the value most likely to be rolled in this case. This should be (roughly?) true in general. Whatever the range of possible values, the most likely value should be the value in the middle of that range.

In our case, the range is n (rolling all 1s) to dn (rolling all ds). So if we want 21 to be the most likely value to get rolled, we want 21 to sit right in that middle.

Thus, for a given d, we want to pick the n that makes (n + dn)/2 as close to 21 as possible.

For D=2, this value is 14, as (14 + 2*14)/2 = 21, which is exactly what we want.

For D=4, this value is 8, as (8 + 4*8)/2 = 20.

As D increases, the range of variation that you get for each additional die is larger, which is why the smaller D values give you the best probability of getting 21. In the extreme case, if you had 1-sided dice you should pick 21 of them, as you'll have a 100% chance of winning.

If we know that we want (n + dn)/2 to be close to 21, that implies that n should be close to 42/(1 + d).

I think there is a function in Number Theory that could give us the number of ways that a whole number (positive integer) X can be written as a sum of N integers from the set {1,2,...,m}. For simplicity, I shall call this number of ways \(F_{m,N}(X)\).

Given an n-sided die Dn (with numbers labeled by {1,2,...,m}), and given that you would choose N such die, the sample space size is \(m^N\). So the probability of rolling a total of X is

\(\Large{\frac{F_{m,N}(X)}{m^N} }\).

If the function F could be identified from Number Theory, then these probabilities can be calculated for the case at hand for \(m = 4, 6, 8, 10, 12\) and see which of these has the larger value for various N (and what N is for each given m). One should then be able to see which gives the greater probability.

From Number Theory we know that the number of distinct rolls of n d-sided dice is \({d+n-1}\choose{d}\). In this case distinct means that rolling a 1 on the first dice and a 4 on the second is the same as rolling a 4 on the first and a 1 on the second. I don't know if that's what we want to count, but if so it would probably be our denominator instead of \(d^n\).

Yes, you can do it that way too. I just find it bit easier as I described since you can write down the sample space more directly. If there are repeats or multiplicities, they would cancel out when working out the probabilities.

I'd like to propose a breakdown of the problem to a simpler one if I may. Just consider the D4 case - that of 4 sided dice. The question would now be: how many die of this type would be the best strategy? As EN noted, you'd have to have at least 6 of them. Does 6 give the greatest probability for the sum to be 21? Or would it be 7? 8? etc.

I worked out the probability for 6 die of type D4 to add up to 21. I got

It will probably also increase if you choose 8 die. However, as EN observed, choosing 22 die will never give a sum of 21. And even 21 die will yield only one event in a sample space of size \(4^{21}\) which is hugely small! So I think we can make a reasonable guess that the number of die should be the middle between 5 die (which gives zero probability) and 22 (which also gives 0 probability). What number lies in the middle of these? I'd pick 14 die of type D4 to give the greatest probability in the D4 subproblem. Just my guess if this thing grows like a binomial distribution.

I bet you can do the same for the other die types -- pick out the middle number of die and compare those middles.

Xhin, EN, does this makes sense? Does it agree with your calculations?

Xhin: Interesting, it looks like 8d4 is the best, at least statistically.

My calculations would seem to agree. But 9, 10, ... 14 might even get progressively better. But I'm not certain! Since the probability will have to go back down to 0 with 22 die (of type D4), it would seem that the closer we are to 19, 20, 21 die the smaller the probability becomes. It's like a normal distribution that goes up for a while and then goes back down.

Let's do a simpler problem first. We have to stop thinking of 21 for the moment since the problem depends on other of its 'subintegers'. Take any positive integer M. How many ways can you write it down as a sum of two positive integers from the list {1,2,3,...,n}? I call this number \(W_2(M,n)\). Here is a formula that can probably be checked to see if I got it right:

\(
W_2(M,n) = \begin{cases}
M-1 & if \ \ 2 \le M \le n \\
2n-M & if \ \ n < M < 2n \\
1 & if \ \ M = 2n \\
0 & if \ \ M > 2n \ \ or \ \ M = 1
\end{cases}
\)

It is very case dependent, as you can see. We'll then have to use induction in iterating it to get sums for 3, 4, ... integers. That is, to get \(W_3(M,n), W_4(M,n) ... \) etc in a recursive way since you can write each of them in terms of the previous one.

= Makes paragraph bolded
// Makes paragraph italic

!cyan Makes paragraph cyan
!yellow Makes paragraph yellow
!red Makes paragraph red
!green Makes paragraph green
!purple Makes paragraph purple
!pink Makes paragraph pink
!orange Makes paragraph orange

!=cyan Makes paragraph bolded cyan
!//cyan Makes paragraph italicized cyan This works for the other colors above

** Gives a line solid circle bullets

*- Gives a line solid square bullets

*=Gives a line outline circle bullets

[b]TEXT[/b] Bolds text

[i]TEXT[/i] Italicizes text

[s]TEXT[/s] Strikes through text

~(draw)~ and ~(roll)~ and ~(flip)~ work... try them out :P