Skip to content

Instantly share code, notes, and snippets.

Created December 3, 2021 18:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
# Simulation of
from random import randint
import statistics
times = 100000
data = []
# bridge made up of 18 pairs of separated glass squares.
for i in range(times):
# In this round, you are one of the 16 remaining competitors.
alive_competitors = 16
known_squares = 0
while known_squares < BRIDGE_SQUARES:
# everyone died!
if alive_competitors == 0:
# choose one of the two squares in a pair to land on.
square_to_land = randint(0, 1)
if square_to_land == BAD_GLASS:
alive_competitors -= 1
# Once a pair is revealed all remaining competitors take notice.
known_squares += 1
mean = statistics.mean(data)
median = statistics.median(data)
mode = statistics.mode(data)
# On average, how many of the competitors survive and make it to the next
# round of the competition?
print(f'alive competitors: mean: {mean} median: {median} mode: {mode}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment