Problem 53850. Backgammon #4 - Dice Probabilities
Previous problems in this series have looked at how a backgammon board might be represented, and board positions manipulated and displayed. In this problem we take a break from looking at backgammon boards, and turn our attention to dice throws.
Backgammon is played with two standard six-sided dice.
Sometimes it is necessary to understand the chances of obtaining a particular dice throw, for example when trying to determine the risks of leaving a blot (a single stone), or when considering whether to offer or accept a double.
In this problem you are given a 'required' throw from two dice as an input vector - for example if you need to throw a 3 and a 6, the input vector will be:
You have to return the probablility (between 0 and 1) of obtaining such a throw.
Sometimes you only care about the value of one of the dice, so in that case the value of the other dice will be set to zero - for example if you need to throw at least one 2 on the two dice, and don't care what the other dice is, the input vector will be one of:
Again you have to return the probablility (between 0 and 1) of obtaining such a throw.
If the input is not a valid throw, such as:
you should return NaN.
Previous problem in series: Problem 53840. Backgammon #3 - Display a Board Position
Next problem in series: Problem 53780. Backgammon #5 - Valid Move?
Regexp cheats and other cheats are not appreciated and will be blocked if you use them.
Solution CommentsShow comments
Problem Recent Solvers12