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.
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.
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
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.
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!
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).
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)
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.
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.