First to Roll a Six

MEDIUM

Amy and Brad take turns rolling a fair six-sided die. Whoever rolls a "6" first wins the game. Amy starts by rolling first.

  1. What is the theoretical probability that Amy wins? (Conceptual/Mathematical)
  2. Implement a simulation in Python to estimate this probability empirically.

 

Simulation Goal:

Your Python simulation should run a large number of game rounds (e.g., 10,000 or 100,000) and calculate the proportion of rounds won by Amy. This estimated probability should be close to the theoretical probability.

Function Signature for Simulation (Python):

import random

class Solution:
    def simulate_dice_game(self, num_simulations: int) -> float:
        # Your simulation code here
        pass
    
    # Optional: helper function for a single game round
    # def play_one_round(self) -> bool: # Returns True if Amy wins, False otherwise
    #     pass 

 

Nerchuko Academy · Free DS Interview Prep