Find the Most Probable Sum Value or Values, in Rolling N-dice of n Sides
Description:
This kata was thaught to continue with the topic of Tracking Hits for Different Sum Values for Different Kinds of Dice
see at:http://www.codewars.com/kata/56f852635d7c12fb610013d7
In that kata we show the different sum values obtained rolling 3
tetrahedral dice. There is a table that shows how values 7
and 8
are the most probable sum values to obtain, having the highest probability of all, 0.1875
.
Looking the image, if we take dice from a row(up to 7 elements) we will have the same type dice (different colours)
The probability is obtained doing the quotient between the total different combinations and total of cases.
probability(tetraedral_dice, 3, sum) = different_combinations_for_sum / total cases = 12 /(4*4*4) = 0.1875
The function most_prob_sum()
will receive two arguments:
- a string with the type dice, one the following ones:
'tetrahedral', 'cubic', 'octahedral', 'ninesides', 'tensides', 'dodecahedral', 'icosahedral'.
- a number
n
, that is the amount of rolled dice.
The corresponding range for each die are :
'tetrahedral' [1, 4]
'cubic' [1, 6]
'octahedral' [1, 8]
'ninesides' [1, 9]
'tensides' [1, 10]
'dodecahedral' [1, 12]
'icosahedral' [1, 20]
Let's see the output of the function with the given example:
most_prob_sum('tetrahedral', 3) == [[7, 8], 0.1875]
We need a list with two terms, the first one: a sorted list with the most probable sum value(s) and the second one: the maximum probability value.
For this kata we will have more challenging tests than the previous one,so we will need an optimized version for the solution.
More example cases are given in the Example Test Cases box.
Do not round the results for the probability value.
Enjoy it!
Similar Kata:
Stats:
Created | Mar 30, 2016 |
Published | Mar 30, 2016 |
Warriors Trained | 778 |
Total Skips | 188 |
Total Code Submissions | 497 |
Total Times Completed | 165 |
Python Completions | 136 |
JavaScript Completions | 27 |
Ruby Completions | 19 |
Total Stars | 23 |
% of votes with a positive feedback rating | 92% of 42 |
Total "Very Satisfied" Votes | 35 |
Total "Somewhat Satisfied" Votes | 7 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 5 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 6 kyu |