Problem 257399 · easy · Level 02 Linear Data Structures

Two Unusual Dice

probability · equally likely outcomes · counting · fractions

A board game uses two dice with unusual numbers of faces: the first die shows 1 to a and the second 1 to b, each face equally likely. A player moves only if the total of the two dice is at least target.

Write chance_to_move(a, b, target) that returns the exact probability as a tuple (numerator, denominator) in lowest terms. A probability of 0 is (0, 1) and a probability of 1 is (1, 1).

Examples

Input:  a = 6, b = 6, target = 10
Output: (1, 6)
Explanation: 6 of the 36 equally likely pairs have a total of 10 or more:
(4,6) (5,5) (6,4) (5,6) (6,5) (6,6). 6/36 = 1/6.

Input:  a = 4, b = 8, target = 11
Output: (3, 32)
Explanation: only (3,8), (4,7) and (4,8) out of 4 × 8 = 32 pairs.

Constraints

  • 1 <= a, b <= 1000
  • 0 <= target <= 2001

Goals

  • List the equally likely outcomes of rolling two different dice
  • Count the outcomes in an event and divide by the total
  • Give an exact probability as a fraction in lowest terms
Starting Python…