Algorithms to Live By · ch.1 · optimal stopping
⏱ Chapter 1 · When to look, when to leap

When to stop looking

Apartments, applicants, parking spots, partners. Whenever options arrive one at a time and you can't go back, there's a single, surprisingly simple rule. It involves the number 37.

You almost certainly faced a version of it this morning: a stream of choices flying past, and the nagging feeling that the moment you commit to one, the next will be better. Should you settle? Should you hold out? Computer scientists have a name for the family — optimal stopping problems — and one of them has an answer so clean it's almost suspicious.

The whole chapter swings around one number: 37. Where it comes from, why it works, and where it shows up in apartment hunts, dating, parking, and online algorithms.

1The hiring problem nobody wants

You're hiring a secretary. N candidates show up one at a time in random order. After each interview you must decide on the spot — hire them or reject them forever. No going back. No comparing side-by-side. When do you stop looking and commit?

That's it. That's the whole setup. It's called the secretary problem, formulated in the 1950s and famous ever since — partly because the answer is so weirdly specific, and partly because the same shape of problem keeps showing up everywhere else.

🎯
The rules are brutal: no recall (you can't return to a candidate you passed on), no preview (you don't know how many great ones are still coming), and only relative ranks (you can tell A is better than B, but you don't know absolute quality).

2The 37 % rule

Here's the rule:

Look at the first 37 % of candidates without hiring anyone. Then take the next one who beats everyone you've seen so far.

Why 37 %? Because 1/e ≈ 0.368, and that's the threshold that balances the two ways the rule can fail: rejecting the actual best because they fell into your look phase, versus settling too early before the best has even shown up. Tilt the threshold up and you waste good candidates on calibration. Tilt it down and you commit before you know what good looks like. The sweet spot — provably — is the reciprocal of e.

📐
Where does e come from? The same place it always does: large-N limits. The exact probability of picking the best candidate using a look-then-leap rule with cutoff k/N approaches (k/N) · ln(N/k) as N grows. Maximise that, and you get k/N = 1/e. We're going to skip the calculus and just watch it work.

3Look, then leap

The look phase isn't picking — it's calibrating. You're not throwing those candidates away, you're learning what good looks like. Then the moment someone beats your calibration set, you commit.

Two clean phases:

  • Look (first N/e candidates): reject everyone, but remember the best.
  • Leap (the rest): take the first candidate who beats that best-seen-during-look.
Interactive · single-trial walkthrough Step through one run · watch the rule act
12
Ready. N = 12. Look phase = first 4 candidates. Press Step or Run.

4The surprising punchline

Now here's the part that makes the rule famous. Your chance of actually landing the best candidate is also about 37 % — and that's true no matter how big N gets. With 10 candidates or 10 million, the rule wins you the top of the pile around 37 % of the time.

That's a wild bargain. Without the rule, picking randomly nets you the best one with probability 1/N. With 100 candidates that's 1 %. The 37 % rule, with the same information, scores 37 × better.

Interactive · the curve has a peak Empirical from 500 trials per point · N = 50
37
look fraction = 37 % → empirical success ≈ —

5What this looks like in real life

  • Apartment hunting. Got 30 days to view places? Spend the first 11 just looking — turn down everything, no matter how good. Then commit on the next apartment that beats the best you saw in those 11 days.
  • Dating (the "37 % rule of marriage"). If you'll seriously date between age 18 and 40, the look phase ends around 26. After that, commit to the next person who beats every ex.
  • Parking. Drive past the first ~37 % of available spots before considering anything. Then take the next one better than the best you saw.

"You don't need to see all the options. You need to see enough to know what good looks like."

The math is the math. The hard part is trusting the calibration — actually rejecting that very nice 11th apartment, the one you would have been happy to live in.

6Variants worth knowing

The classic 37 % rule assumes the rules at the top of the chapter. Relax any one of them and the answer shifts:

  • Recall allowed. If you can return to earlier candidates (maybe they'll still take the job, maybe they won't), success goes up. The look phase shrinks; the leap phase grows.
  • Full information. If you actually know the score distribution in advance — say candidate quality is normally distributed with known mean and variance — you don't need a calibration phase at all. You set a fixed threshold from the start and accept the first candidate over it. Studied in depth by Robertson & Flannery and by Gilbert & Mosteller.
  • Candidates can reject you. Now it's a two-sided matching problem — closer in spirit to stable-marriage than to optimal stopping.
  • Cost per look. If interviewing costs money, the look phase shrinks again — every look has to be worth its weight.
🧮
The thing to notice: the more you know up front, the less calibration you need. The 37 % rule is the answer when you know nothing about the distribution. It's the no-information baseline — which is exactly why it travels so well to real life.

7Where programmers see optimal stopping

Take the secretary problem and squint. Anywhere data arrives as a stream and you have to decide irrevocably on each item, you're inside an optimal-stopping problem:

  • Online algorithms — the whole class. Inputs come one at a time; you commit per-item without seeing the future.
  • A/B test stopping — when do you stop collecting data? Watch enough, but don't watch forever.
  • Server selection — pick the first server from a rotating list whose latency beats a threshold you calibrated on the first batch.
  • Online hiring — same as the original, just with résumés in a queue.
  • Multi-armed bandits — the first phase of many bandit algorithms (UCB, ε-first) is essentially a look phase before the leap.
Interactive · watch the rule converge Random orderings · uniform scores
50
Trials
0
Best picked
0
Success rate
1/e target
36.79%
0%success rate vs. target100%

8The rule, in seven lines

The algorithm is short enough that the type signature alone tells most of the story: stream in, maybe-pick out. Flip between the two languages — the shapes are nearly identical.

💡
Notice how the algorithm doesn't need to know N up front in any deep way — it only uses length once to split. Everything else is a single pass through the stream. That's why this rule scales to online settings where you decide on items as they arrive.

9Check yourself

3 questions · instant feedback 0 / 3

10What's coming

The secretary problem is one corner of a larger map. The next chapter is its opposite mood: when you can come back, when failure is cheap, when the question stops being "should I commit?" and becomes "should I try something new, or stick with what I already love?"

🎰
Up next · Chapter 2
Explore/Exploit
The latest vs. the greatest. Multi-armed bandits, restaurant choice, and why "trying something new" is mathematically optimal when you've got time, but not when you're about to leave town.