4 kyu

Dice rolls threshold

96 of 150kirilloid

Description:

Stacey is a big AD&D games nerd. Moreover, she's a munchkin. Not a cat breed, but a person who likes to get maximum efficiency of their character.

As you might know, many aspects of such games are modelled by rolling dice and checking it against a threshold value determined by various aspects. Stacey wants to always control the situation and know whether she can beat the foe with certain special ability or not. Unfortunately she doesn't know probabilty theory well enough. Help Stacey by providing a calculating utility for her.

P.S.: Stacey says that she has tried to implement a calculator by Monte-Carlo modelling: calling rand() in a loop, but she hasn't been satisfied with precision of this method.

Examples

P(1d6 >= 4) means the chance of getting 4 points or higher on a regular cubic die. Obviously the chance is 3/6 cause there're 6 possibilities in total (1, 2, 3, 4, 5, 6) and only three of them are >= 4: (4, 5, 6)

P(2d6 >= 3) gives us 35/36, cause the only possibility to get < 3 is rolling exactly 1+1. Exactly 2 as sum of two dice appears only if both have 1. While total amount of different outcomes is 6*6 = 36. Hence resulting probability is 1-1/36, which is 35/36

Your task

is to write a function, which will calculate the probability of that a die with N sides rolled M times (MdN in AD&D notation) will get at least T points. We don't add modifiers cause they are already incorporated into the threshold.

Input arguments will be valid integers with the following limits:

  • rolls 1..20
  • sides 2..100
  • threshold 1..2000
Probability
Combinatorics
Algorithms

More By Author:

Check out these other kata created by kirilloid

Stats:

CreatedAug 17, 2015
PublishedAug 18, 2015
Warriors Trained1110
Total Skips207
Total Code Submissions2778
Total Times Completed150
JavaScript Completions44
Haskell Completions14
Python Completions96
Ruby Completions13
Total Stars72
% of votes with a positive feedback rating95% of 47
Total "Very Satisfied" Votes43
Total "Somewhat Satisfied" Votes3
Total "Not Satisfied" Votes1
Total Rank Assessments6
Average Assessed Rank
3 kyu
Highest Assessed Rank
3 kyu
Lowest Assessed Rank
4 kyu
Ad
Contributors
  • kirilloid Avatar
  • Voile Avatar
  • BabyPowder Avatar
Ad