Chapter 199
Two Paths Diverged In A City And I, I Took The Block Less Traveled By
Riddler Express
Major League Baseball’s playoffs use a single-game wild card round, then best-of-five Division Series, best-of-seven League Championship Series, and best-of-seven World Series. What is the highest possible regular-playoff winning percentage a team can post without winning the World Series? What is the lowest possible playoff winning percentage a team can post while winning the World Series? Extra credit: how close to these extremes has any team come?
The Riddler, FiveThirtyEight, September 21, 2018(original post)
Solution
Maximum without a ring. Win every game possible until the final loss in the final series. To maximise wins, take the wild card route (an extra forced win): one wild-card win, sweep the Division Series -, sweep the League Championship -, then push the World Series to seven games but lose it -. Totals: wins and losses.
Minimum with a ring. Skip the wild card (a division winner does not play one) and eke out every series: Division Series -, League Championship -, World Series -. Totals: wins and losses. Eleven wins is forced from the other side too: the road to the trophy demands three series wins of , and games respectively.
Extra credit. The 2014 Kansas City Royals achieved the bleak record for losing finalists almost exactly: a wild-card win against the Athletics, a - sweep of the Angels, a - sweep of the Orioles, then dropping the World Series - to the Giants. Their record is -, hitting the ceiling. The 2017 Houston Astros came close to the eke-it-out record: - over the Red Sox, - over the Yankees, - over the Dodgers (winning the World Series). Their playoff record was - for , just shy of the floor.
The computation
Exhaustively enumerate all feasible playoff itineraries (each series an ordered set of wins and losses) and compute the win/loss percentages directly, separated by whether the World Series was won. The maximum among the non-winners and the minimum among the winners are the targets.
Enumerate the four series independently: wild card ; Division Series outcomes ; likewise LCS and WS over .
For each itinerary, the team participates iff it wins every prior series. Compute total wins/losses; flag whether the World Series was won.
Track the maximum winning rate among non-winners and the minimum among winners.
def series_outcomes(N):
# best of (2N-1) game results, as (wins, losses) for the team's record
out = []
for w in range(N + 1):
for l in range(N + 1):
if max(w, l) == N and min(w, l) < N:
out.append((w, l))
return out
DS = series_outcomes(3) # best of 5
LCS = series_outcomes(4) # best of 7
WS = series_outcomes(4) # best of 7
best_no_ring = 0.0
best_no_ring_rec = None
worst_with_ring = 1.0
worst_with_ring_rec = None
for wc in [None, ('W',), ('L',)]:
if wc is None:
w0, l0, alive = 0, 0, True
elif wc == ('W',):
w0, l0, alive = 1, 0, True
else:
w0, l0, alive = 0, 1, False
if not alive:
continue
for dw, dl in DS:
if dw < 3: continue
for lw, ll in LCS:
if lw < 4: continue
for sw, sl in WS:
W = w0 + dw + lw + sw
L = l0 + dl + ll + sl
pct = W / (W + L)
ring = sw == 4
if ring:
if pct < worst_with_ring:
worst_with_ring = pct
worst_with_ring_rec = (W, L)
else:
if pct > best_no_ring:
best_no_ring = pct
best_no_ring_rec = (W, L)
print(f"Best no-ring: {best_no_ring_rec} = {best_no_ring:.4f}")
print(f"Worst with ring: {worst_with_ring_rec} = {worst_with_ring:.4f}")
The script prints - and -.
Riddler Classic
Your office is at the corner of a perfect city grid, and your apartment is five blocks west and ten blocks south of the office. You walk to and from the office along the streets, never taking a path longer than necessary. You insist on taking a different path each walk. How many days can you keep this up before you are forced to repeat a path? Extra credit: how does the answer scale if you live blocks west and blocks south of the office?
The Riddler, FiveThirtyEight, September 21, 2018(original post)
Solution
A shortest path from apartment to office goes only east and north, exactly five east blocks and ten north blocks. Each path is a sequence of fifteen moves with five E’s and ten N’s, and the number of such sequences is Reversing a path (walking it from office back to apartment) traces the same set of street segments in the opposite direction. The puzzle says "a different path along the streets each time", and the natural reading is that a path is the geometric route, so a sequence and its reverse describe the same path of streets. (The other reading, that a directed sequence counts as its own path, gives days of two unique walks each but doubles to uses; this matches less of the puzzle’s spirit.)
Each day the walker uses two of these routes (morning and evening). With routes available, the largest number of days with two fresh routes per day is On day only one fresh route remains, forcing a repeat for the second leg. Hence
Extra credit. For an apartment blocks west and blocks south, the number of shortest paths is the binomial coefficient . Days of unique double-walks are . For the count is , giving days, or roughly years. The path count grows much faster than linearly: doubling each dimension roughly squares the result for large , by the central-limit / Stirling estimate .
The computation
Enumerate the paths directly as binary strings with five s and ten s; count and confirm . As a sanity check, compute it from the binomial coefficient formula.
Iterate over all length- binary strings with exactly ones; count.
Cross-check against and divide by for the day count.
Print for a small table of values.
from math import comb
from itertools import combinations
# Direct enumeration over length-15 binary strings with five 1s
n_paths = sum(1 for _ in combinations(range(15), 5))
print(f"Length-15 paths with 5 east moves: {n_paths}")
print(f"binom(15, 5) = {comb(15, 5)}")
print(f"Days of unique double-walks: {n_paths // 2}")
print("\nExtra credit table:")
for M, N in [(5, 10), (10, 10), (15, 10), (10, 20), (20, 20)]:
p = comb(M + N, N)
print(f" M={M}, N={N}: paths={p:>10}, days={p // 2}")
The script prints paths and days, and tabulates the extra credit binomial coefficients.