Optimal Stopping with Square-Number Ruin
Jane StreetSoftware Engineer · Technical ScreenLast updated
Analyze an optimal stopping game where a player rolls a fair six-sided die to accumulate points but busts if the running sum hits a positive perfect square. Tests dynamic programming, renewal theory intuition, and rigorous edge-case analysis under uncertain stopping boundaries.
Scenario
You are offered a game played with a single fair six-sided die (faces 1 through 6). The game starts with a running sum of S = 0.
On each turn:
- You roll the die and add the outcome to your running sum
S. - Ruin Condition: If the new sum
Sis a positive perfect square (S in {1, 4, 9, 16, 25, ...}), you immediately bust. The game ends, and your payout is0. - Stopping Decision: If
Sis not a perfect square, you may choose to either stop and bank your current score (receiving a payout equal toS), or roll the die again.
Tasks
1. Dynamic Programming & Value Formulation
- Define the value function
V(s), representing the maximum expected payout achievable from a non-busting states. - State the Bellman optimality equation for
V(s). - Explain whether the game has a finite or infinite optimal expected payout. In particular, discuss the survival probability of crossing the
k-th square ask -> inf.
2. Early-State Evaluation
- Suppose you take your first roll from
S = 0. With probability 2/6, you bust immediately on 1 or 4. - For the non-busting initial rolls (
S in {2, 3, 5, 6}), determine whether it is optimal to stop immediately or continue rolling. Derive the one-step lookahead comparison and explain any assumptions required to bound future expectations.
3. Asymptotic Policy & Edge Cases
- As
Sgrows very large, the distance between consecutive squaresk^2and(k+1)^2expands as2k + 1. Describe how the optimal policy behaves in the "middle" of a wide interval between two distant squares versus when approaching the next square boundary. - How does the optimal policy change if:
- A bust only resets the score by a fixed penalty rather than setting the total payout to zero?
- The die has faces
0to5instead of1to6?
Hints
Hint 1
Notice that the probability of hitting any specific integer in a renewal process with average step size 3.5 approaches 1 / 3.5 = 2/7 as the distance from the starting point increases.
Hint 2
Because the probability of hitting a square upon crossing it is roughly bounded away from 0, the probability of surviving n consecutive square crossings decays exponentially, while the reward scales at most quadratically.
Hint 3
For the first roll decision, compare the guaranteed payout of stopping at s in {2, 3, 5, 6} against the expected value of rolling again, noting that from s = 2, you risk busting on 4 (with roll 2) or 9 (impossible in one roll, but reachable later).
Follow-up questions
- What is the exact asymptotic probability of hitting the square k^2 conditional on surviving past (k - 1)^2 as k becomes arbitrarily large?
- If you were allowed one 'free pass' (forgiving your first bust), how would that affect your threshold for stopping in the first few intervals?
- Could this problem be solved numerically using value iteration, and what truncation point S_max would guarantee that the error on V(0) is below 0.01?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.