Equation

Pages: 12
I have tried to make a program, which simulates a 12 sided dice. This I have accomplished. Now I have to calculate the probabillities of landing on a single number for this I have to put in this formel ((23*x)/1*x*(23-1)*x)*((1/144)^1)*1-(1/144)^23-2

I just can't find a way to get the correct result.

Can anyone help me with this problem?
Last edited on
Oh my... (1/144)^23 is quite some precision requirement. It has nearly 50 leading zeroes. I'm not sure standard C++ types have the precision you require.

By the way, are you sure your formula is correct? There are some weird things in it. I see a division by 1, a 1 as exponent and a multiplication by 1. Seems very odd.
Last edited on
The program is like this: 2 12 sided dice are rolled 23 times. A player have to guess a number which he thinks will be rolled and then how many times he thinks it will appear.

The formula looks like this: (n!/x!(n-x)!)*p^x*q^(n-x)

n = 23 (number of times the dices is rolled)

! = faculty(23)

x = 1 (number of times the player thinks the number will appear)

p = 1/144 (the likelyhood of the number to appear when the dices are rolled once.)

q = 1-p

I may have forgotten a few parentheses in the first post and the last number 2 should be 1
Last edited on
Then your formula in the first post is very much wrong, even with proper parentheses and the number swap. How could "23*x" ever appear in the equation? Also, it seems like you sometimes replaced 'x' with '1' and then randomly inserted the 'x' back in other places.

Also, rolling 2 12sided dice 23 times is the same as rolling a single 12sided dice 46 times, if all you're doing is calculating the total amount of "V appeared". Unless you want a combined chance (e.g. "count how many times both dice show '5'"), it's much easier to see them as separate events.
I am calculating the probabillity. For instance 13 appearing 4 times in the 23 rolles.

My problem is I can't figure out how to put in the equation so I get the correct result
Ah, my bad, I thought you were simply considering the number of eyes on each die; the sum, of course, makes much more sense.

Anyway, the calculation in C++ is just the same as on paper:
-Given the input (n, x, p)...
-Assign val <-- chance(n, x, p)
-... with chance() defined as the formula.

If your output is wrong, and your code correct, then either your formula is wrong (seems very likely), or it's a precision problem (as said: (1/144)^(21) is a VERY small number!). Without showing us your code, we can't help you determine which it is!
The formula is correct I have tried it in excel and one other math program.

x0 is faculty(23)

((23*x0/(1*x0)*(23-1)*x0))*pow(1/144,1)*pow(1-1/144,23-1) I tried this, but it didn't work
Your formula still doesn't make sense. 23*fac(23)? Where would that ever come from? In fact, the entire first half just doesn't make any sense to me (up until the first power).

Here's what your function looks like in symbols:

(n *  (  n!  ) * (n-1) * n!) * (1/144)^(1) * (143/144) ^ (23-1)
         -----
         1*n!

Where do you keeping getting those x0's/23!'s? The formula only has one. According to the formula you provided in your second post, the formula should be this: (for x = 1)
n * p * (1-p)^(22)
the first half is like this in symbols: (n*!)/(x*!)*(n-x)*!

where x is 1, n is 23 and ! is fac(23)
closed account (o1vk4iN6)

p = 1/144 (the likelyhood of the number to appear when the dices are rolled once.)


Are you taking the sum of the two dices, if so than this wouldn't be true, a number like 24 would only have a 1/144 chance to be rolled, but a number like 5 has a 4/144 chance to be rolled.

My probability is a bit rusty though.

I don't see how you can implement the number of times the user "thinks" a number will be rolled. That in itself would be changing the probability of which a number could be rolled and that becomes simply a guess.
Last edited on
@peter:
That's not what your formula said:
The formula looks like this: (n!/x!(n-x)!)*p^x*q^(n-x)

n!/(x! * (n-x)!) is known as "Combination of x out of n", which to make makes sense to use here. What you're doing in your last post is something entirely different.

@xerzi:
That's not what he's doing. He's simply calculating the chance of a certain number being rolled X times. I think he accounted for the difference in chance per number by the 'p' value. Seeing he chose 1/144, I'm assuming he's calculating the chance that '2' or '24' appears X times.

Forgot to add: the Comb(n, 1) is always simply 'n'. Mathematically:
n!/( 1! * (n-1)!) = n*(n-1)! / (n-1)! = n.
Inuitively: "In how many different ways can I select 1 element out of n elements?" --> In 'n' ways, as each element can be selected in only one way, and there are 'n' distinct elements.
I know the formula is right (the one I wrote in my second post), I maybe doing it wrong.. I just assumed that n! meant n*!
closed account (o1vk4iN6)
@Gaminic

That's what I thought too until I saw what he said x was:

x = 1 (number of times the player thinks the number will appear)

I haven't really been paying close attention, but I saw something that nobody else seems to have mentioned yet.

(1/144) is zero. If you want floating point division you need a floating point number:
(1.0/144.0)
@Disch

1/144 is not zero it is 0,00694
1/144 is not zero it is 0,00694

Is that so? Then what does the following print?
cout << 1/144 << endl;

Read more carefully.
you have to make sure that you get (double) numbers and not int
That's what Disch said.
But thats not my problem... I still need a way to write the formula in c++
Pages: 12