Skip to content

Instantly share code, notes, and snippets.

@bschneidr
Last active July 21, 2017 16:54
Show Gist options
  • Save bschneidr/b03abdf1b59a0d7bf75f1bb2d53f145f to your computer and use it in GitHub Desktop.
Save bschneidr/b03abdf1b59a0d7bf75f1bb2d53f145f to your computer and use it in GitHub Desktop.
Solution to July 14, 2017 Riddler Classic
# Set the parameters which are beyond the player's control
prob_win <- 0.6
alpha <- 1000000L
beta <- 10000L
# List the possible choices available to the player
minimum_games <- 1L:50L
# List the series lengths which result from each available choice
# and, for each choice, list the corresponding probability of winning the series
series_lengths <- (2*minimum_games) - 1
prob_win_champ <- 1 - pbinom(q = minimum_games - 1,
size = series_lengths,
prob = prob_win,
lower.tail = TRUE)
# For each choice available to the player, define the payoffs if they win or, alternately, lose
payoff_if_win <- alpha - beta*minimum_games
payoff_if_lose <- 0
# Calculate the expected payoff for each choice
expected_payoff <- (prob_win_champ)*payoff_if_win + (1 - prob_win_champ)*payoff_if_lose
# Return the choice of series length which maximizes the player's expected payoff
series_lengths[expected_payoff == max(expected_payoff)]
# Return the best expected payoff
max(expected_payoff)
# Plot the payoff curve
plot(series_lengths, expected_payoff)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment