For a game, I am trying to determine the frequency that will show # on the given # loop given to the fixed number. I know ... this question sounds strange. Try to explain it to me with real numbers.
So, to die 1, the frequency of each number will be the same. An equal number will be displayed in 1-6.
Now for 2 dice, things are different. I imagine that 5,6,7 are going to be most often rolled, whereas the number of both ends of the spectrum will be less or less (in case of 1) I want to know how to calculate this list and To show them in the proper order, at least often the least.
Any thoughts?
@ Duffimo - it would be really good, though it would have to be some sort of algorithm to come along. It seems that by lifting the hands above and keeping the numbers in the above manner, it is necessary. If my death number is dynamic, to say 10, that it will be impossible and trouble by hand, I think. :)
To do this, some format in a recursive format:
Public Fixed IEnumerable & lt; KeyvaluePair & lt; Int, int & gt; & Gt; GetFrequenciesByOutcome (int nDice, int nSides) {int maxOutcome = (nDice * nSides); Dictionary & lt; Int, int & gt; Results = New Dictionary & lt; Int, int & gt; (); For calculation [i] = 0; (int i = 0; i & lt; = maxOutcome; i ++) for the result; Foreign currency (possibly the result in GetAllOutcomes (0, nDice, nSides)) calculation [possibleOutcome] = outcomeCounts [possibleOutcome] + 1; Return result count. Where (kvp = & gt; kvp.Value & gt; 0); } Private Stable IEnumerable & lt; Int & gt; GetAllOutcomes (int presenttal, int nds, int nsides) {if (NDCE == 0) yield yields returns; Else {for (ii = 1; i & lt; = nsides; i ++) difference in foreach (GetAllOutcomes (Current Total + i, nDice-1, nSides)) yield yield results; }}
As long as I'm not mistaken, organized keywairs should be spitting in the form of [key, frequency].
Edit : FYI, after running it, shows frequencies for GetFrequenciesByOutcome (2, 6):
2: 1
3: 2
4: 3
6: 5
7: 6
8 : 5
9: 4
10: 3
11: 2
12: 1
Comments
Post a Comment