This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Code to help answer the Riddler Express from 11/13/2020: | |
# https://fivethirtyeight.com/features/can-you-snatch-defeat-from-the-jaws-of-victory/ | |
from fractions import Fraction | |
import random | |
TOTAL_ON_BOARD = (2 + 4 + 6 + 8 + 10) * 100 * 6 # Total amount a Jeopardy! board is worth | |
def get_exp_value(call_order): | |
""" | |
Takes a list of 30 amounts corresponding to the values of answers chosen and | |
returns the expected value (as a fraction) for the return if you answer every | |
question correctly and bet the maximum amount on a daily double. | |
""" | |
left_on_board = TOTAL_ON_BOARD | |
money_on_hand = 0 | |
exp_value = Fraction(0, 1) | |
for amount in call_order: | |
# 1/30th of the time, we hit the daily double here | |
bet_amount = max(money_on_hand, 1000) | |
total_won = money_on_hand + bet_amount + (left_on_board - amount) | |
exp_value += Fraction(total_won, 30) | |
money_on_hand += amount | |
left_on_board -= amount | |
return exp_value | |
# Answer the original question: what happens if you go in order across the columns, | |
# from the lowest to the largest values: | |
amounts = [] | |
for amount in range(200, 1001, 200): | |
amounts.extend([amount] * 6) | |
exp_value = get_exp_value(amounts) | |
print("Across, top to bottom:", exp_value, float(exp_value)) | |
# Not asked, but interesting: what happens if you go from top to bottom, | |
# and what happens if you go category by category, from top to bottom and bottom | |
# to top. | |
amounts = [] | |
for amount in range(1000, 100, -200): | |
amounts.extend([amount] * 6) | |
exp_value = get_exp_value(amounts) | |
print("Across, bottom to top:", exp_value, float(exp_value)) | |
amounts = list(range(200, 1001, 200)) * 6 | |
exp_value = get_exp_value(amounts) | |
print("Category, top to bottom:", exp_value, float(exp_value)) | |
amounts = list(range(1000, 100, -200)) * 6 | |
exp_value = get_exp_value(amounts) | |
print("Category, bottom to top:", exp_value, float(exp_value)) | |
# Extra credit, what happens with a random order. | |
# Try 100000 random games | |
N_GAMES = 100000 | |
exp_value = Fraction(0, 1) | |
amounts = list(range(200, 1001, 200)) * 6 | |
for _ in range(N_GAMES): | |
random.shuffle(amounts) | |
exp_value += get_exp_value(amounts) / N_GAMES | |
print("Random Walk:", exp_value, float(exp_value)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment