#406 · Math · Advanced · 150 XP · about 30 min
You roll dice fair dice, each with faces numbered 1 to sides. What is the probability that the faces add up to exactly total?
Write dice_probability(dice, sides, total) that returns the exact probability as a string 'p/q' in lowest terms. An impossible total gives '0/1', and a certain one gives '1/1'.
dice_probability(2, 6, 7) # returns '1/6' dice_probability(3, 6, 10) # returns '1/8' dice_probability(1, 6, 7) # returns '0/1'
Two ordinary dice make 7 in 6 of their 36 equally likely outcomes, so the answer is 6/36 = 1/6.
First solves only, ranked by stars and then time.