Skip to content

Instantly share code, notes, and snippets.

@pgk
Created Dec 3, 2021
Embed
What would you like to do?
# Simulation of https://fivethirtyeight.com/features/can-you-survive-squid-game-riddler/
from random import randint
import statistics
times = 100000
data = []
# bridge made up of 18 pairs of separated glass squares.
BRIDGE_SQUARES = 18
BAD_GLASS = 1
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:
break
# 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
data.append(alive_competitors)
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