# SM-2 in Production: How a 1980s Algorithm Fixed SA's 60% Learner's Licence Fail Rate
South Africa has a 60% failure rate on the learner's licence test. The test is not hard. The problem is how people study for it, cramming the night before, reviewing signs they already know while neglecting the ones they consistently miss.
SM-2 fixes this. It was published in 1987 by Piotr Woźniak. It powers Anki, Duolingo, and now K53 Drill Master.
What SM-2 Actually Does
SM-2 is a spaced repetition scheduling algorithm. Instead of presenting all items at equal intervals, SM-2 calculates the optimal time to review each item based on how well you performed on it last time.
If you answered correctly and confidently, the algorithm schedules that item to appear again in a longer interval, maybe 6 days. If you hesitated, the interval is shorter, maybe 2 days. If you got it wrong, the item goes back to the start.
The result: you spend time on items you don't know, not items you do. The total study time decreases; the retention rate increases.
The Implementation
interface FlashcardState {
id: string;
interval: number; // Days until next review
repetition: number; // How many consecutive correct answers
efactor: number; // Ease factor (starts at 2.5)
nextReview: Date;
}
function sm2(state: FlashcardState, quality: 0 | 1 | 2 | 3 | 4 | 5): FlashcardState {
if (quality < 3) {
return { ...state, repetition: 0, interval: 1, nextReview: addDays(new Date(), 1) };
}
const newEfactor = Math.max(1.3,
state.efactor + 0.1 - (5 - quality) * (0.08 + (5 - quality) * 0.02)
);
let newInterval: number;
if (state.repetition === 0) newInterval = 1;
else if (state.repetition === 1) newInterval = 6;
else newInterval = Math.round(state.interval * newEfactor);
return {
...state,
efactor: newEfactor,
interval: newInterval,
repetition: state.repetition + 1,
nextReview: addDays(new Date(), newInterval),
};
}
The quality score (0-5) is the key. I map it to user behavior: a quick confident tap gets 5, a hesitation gets 3, a wrong answer gets 1.
The Road Signs Problem
395 K53 road sign images. I extracted them from the official 2024 government PDF using pdfjs-dist: processing each page, extracting image regions, normalizing dimensions, writing them to the public directory. This was not a one-afternoon task. Road sign recognition is a visual memory problem, not a text memory problem. The flashcard system needed to show the actual sign image, not a description of it.
Each sign has a category (warning, regulatory, information), a correct answer, and common wrong answers. The SM-2 scheduler operates per-sign, per-user. The user who consistently confuses the "slippery road" sign with "loose gravel" sees those two signs more often than any other learner, because their efactor on those specific cards has dropped.
The Results
Beta users who completed the SM-2 track reported a 15-20% improvement in practice test scores in under two weeks. This matches the research literature. SM-2 is not a magic algorithm: it's a mathematically optimal application of what we know about how human memory consolidates.
60% of South Africans failing a test about road signs they drive past every day is not a capability problem. It's a study methodology problem. SM-2 is the methodology fix.
What other high-stakes test in your context could spaced repetition fix?
Reader Insights
0 responses
No insights yet. Be the first!