Licence Plates
Oregon licence plates consist of three letters followed by a three-digit number (000 to 999). While driving to work you play a game: each plate you see gives you its three-digit number N; if you ha...
Problem Statement
This archive keeps the full statement, math, and original media on the page.
Oregon licence plates consist of three letters followed by a three digit number (each digit can be from [0..9]).
While driving to work Seth plays the following game:
Whenever the numbers of two licence plates seen on his trip add to 1000 that’s a win.
E.g. MIC-012 and HAN-988 is a win and RYU-500 and SET-500 too (as long as he sees them in the same trip).
Find the expected number of plates he needs to see for a win.
Give your answer rounded to 8 decimal places behind the decimal point.
Problem 371: Licence Plates
Mathematical Foundation
The plate numbers partition into:
- 499 complementary pairs for .
- The self-complementary number 500, since .
- The inert number 000, which has no complement in .
We model the process as a Markov chain with state where counts the number of complementary pairs with exactly one element seen, and indicates whether plate 500 has been observed.
Theorem (Transition Probabilities). From state , the next plate (drawn uniformly from 1000 values) produces the following transitions:
Case (plate 500 not yet seen):
- Win with probability (seeing the complement of one of the active singletons).
- Transition to with probability (seeing plate 500 for the first time).
- Transition to with probability (seeing a new element from an untouched pair).
- Stay at with probability (seeing 000, or re-seeing an already-active singleton).
Case (plate 500 already seen):
- Win with probability (seeing a complement of an active singleton, or seeing 500 again).
- Transition to with probability .
- Stay at with probability .
Proof. There are 1000 equally likely plate numbers. In state :
- Exactly numbers are complements of active singletons (winning numbers from pairs).
- If , plate 500 itself is also a winning number (since ), giving winners total.
- If , plate 500 is a non-winning unseen special number: 1 such number.
- The untouched pairs contribute fresh numbers.
- Plate 000 is always inert (1 number).
- The active singletons themselves, if re-seen, do nothing (these numbers are already counted as seen).
Summing in case : . Check: .
Summing in case : . Here the wasted includes 000, re-seen singletons, and re-seen 500 (but 500 wins, so actually the waste count for is: 000 plus re-seen singletons , and the winning numbers include complements plus 500). Total: .
Lemma (Recurrence). Let denote the expected number of additional plates needed from state . Then:
Proof. Conditioning on the next observation:
Rearranging: , giving the first equation. The derivation for is analogous.
Lemma (Base Case). and .
Proof. At , all pairs are active. With , win probability is , and no new pairs exist, so . With , .
Editorial
Expected number of plates to observe before seeing a pair summing to 1000. We enumerate the admissible parameter range, discard candidates that violate the derived bounds or arithmetic constraints, and update the final set or total whenever a candidate passes the acceptance test.
Pseudocode
E1[499] = 2.0
E0[499] = 1002.0 / 500.0
for k = 498 downto 0:
E1[k] = (1000 + 2*(499 - k)*E1[k+1]) / (999 - k)
E0[k] = (1000 + E1[k] + 2*(499 - k)*E0[k+1]) / (999 - k)
Return E0[0]
Complexity Analysis
- Time: where , i.e., in terms of the fixed problem size.
- Space: for storing the two arrays (reducible to since we iterate downward and only need the next value).
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
int main(){
// E(k, s): expected plates from state (k, s)
// k = number of active complementary pairs (one element seen)
// s = whether 500 has been seen
// Pairs: (1,999),(2,998),...,(499,501) -> 499 pairs
// 500+500=1000 special, 000 irrelevant
// E(k,1) = (1000 + 2*(499-k)*E(k+1,1)) / (999-k)
// E(k,0) = (1000 + E(k,1) + 2*(499-k)*E(k+1,0)) / (999-k)
// Base: E(499,1) = 1000/500 = 2
// E(499,0) = (1000 + 2) / 500
vector<double> E0(500, 0.0), E1(500, 0.0);
E1[499] = 1000.0 / 500.0;
E0[499] = (1000.0 + E1[499]) / 500.0;
for(int k = 498; k >= 0; k--){
E1[k] = (1000.0 + 2.0*(499-k)*E1[k+1]) / (999.0 - k);
E0[k] = (1000.0 + E1[k] + 2.0*(499-k)*E0[k+1]) / (999.0 - k);
}
printf("%.8f\n", E0[0]);
return 0;
}
"""
Problem 371: Licence Plates
Expected number of plates to observe before seeing a pair summing to 1000.
"""
def solve():
# E(k, s): expected additional plates from state (k, s)
# k = number of active pairs, s = whether 500 has been seen
# 499 complementary pairs: (1,999), (2,998), ..., (499,501)
# 500 is special: 500+500=1000
# 000 is irrelevant (no plate 1000)
E0 = [0.0] * 500 # s=0
E1 = [0.0] * 500 # s=1
E1[499] = 1000.0 / 500.0
E0[499] = (1000.0 + E1[499]) / 500.0
for k in range(498, -1, -1):
E1[k] = (1000.0 + 2.0 * (499 - k) * E1[k + 1]) / (999.0 - k)
E0[k] = (1000.0 + E1[k] + 2.0 * (499 - k) * E0[k + 1]) / (999.0 - k)
print(f"{E0[0]:.8f}")
if __name__ == "__main__":
solve()