The Algorithm

How K2 漢字 Works

A rejection sampling algorithm that uses the mathematics of cooling metals to teach you Japanese kanji at the speed of thought.

Erik Bethke · March 15, 2026
• • •

The Origin Story

In 1995, I was a software engineer trying to learn Japanese kanji. Like everyone else, I started with flashcards. And like everyone else, I hit the wall. There are over 2,000 kanji in common use. Traditional flashcard systems felt like shoveling sand with a teaspoon.

I had a copy of Numerical Recipes on my desk — the bible of scientific computing — and I'd been reading about Monte Carlo methods. Rejection sampling, importance sampling, Markov chains. These were techniques for solving hard problems by throwing dice in clever ways. And it hit me: learning is a hard problem. What if I threw dice at it?

So I built a program. Instead of scheduling flashcard reviews on a calendar, I gave each kanji a number — a probability of being selected. Get it right, the number goes down. Get it wrong, it goes up. The program would pick kanji randomly, but weighted toward the ones I was struggling with.

The result was dramatic.

I sat down one weekend and said, "I'm going to learn Kanji." In a six-hour session on Saturday and a six-hour session on Sunday, I went from knowing 100 kanji to 800 kanji in 12 hours. It really was the closest to feeling like that stuff in The Matrix when Neo just downloads information. It felt like I was going just as fast as my brain was able to fold in the new information and update the model.

700 kanji in 12 hours. That is not incremental improvement. That is a different kind of learning. Six hours felt like one hour. That is the definition of flow state.

And at the end, I had 700 new kanji in my head. Not memorized temporarily — actually learned. I could recognize them, read them, understand their components. The knowledge stuck.

The program worked. But I didn't fully understand why it worked so well. Not until thirty years later.

• • •

The Algorithm, Simply Explained

K2 is surprisingly simple. The entire engine is about 50 lines of code. Here is how it works, explained without any math.

Step 1: Every kanji gets a number

When a kanji enters your learning pool, it starts with a selection probability of 0.5 (50%). Think of this number as "how much attention this kanji needs." High number = needs lots of attention. Low number = you've got this one down.

Step 2: The dice roll

To pick the next kanji to quiz you on, K2 does something that sounds almost too simple to work:

  1. Pick a kanji at random from your active pool.
  2. Roll a random number between 0 and 1.
  3. If the random number is less than that kanji's probability, quiz it. Otherwise, throw it back and try again.

This is called rejection sampling — a foundational technique in scientific computing. You are sampling from a non-uniform distribution by accepting or rejecting uniform samples. The kanji you are struggling with (high probability) get accepted more often. The ones you have mastered (low probability) almost never make it through.

Step 3: Update after each answer

This is where the magic happens:

  • Got it right? Halve the probability. (0.5 → 0.25 → 0.125 → ...)
  • Got it wrong? Double the probability. (0.125 → 0.25, or all the way up to 1.0)

That is the entire update rule. Two operations: divide by two, or multiply by two. No complex scheduling. No timestamps. No "review this card in 3 days at 2:15 PM."

Step 4: Grow the pool

After each answer, K2 checks: has the learner mastered everything currently in the pool? Specifically, it checks whether the highest probability in the pool has dropped below a threshold (0.2). If so, you have demonstrated command of the current material, and a new kanji enters the pool at probability 0.5.

This is automatic curriculum progression. You never decide when to add new material. The algorithm senses when you are ready and introduces it. Too easy? Here is new material. Struggling? Focus on what you have until you have got it.

• • •

Why This Works: The Elegant Dynamics

Mastered items become invisible

Every correct answer halves the probability. After three correct answers in a row:

0.5 → 0.25 → 0.125 → 0.0625

At 0.0625, K2 will reject this kanji 94% of the time. It is still in the pool, but it almost never gets selected. Mastered items fade gracefully into the background. They are not gone — they can always resurface if you start getting them wrong again — but they stop taking up your time and attention.

Struggling items demand attention

Conversely, every wrong answer doubles the probability. Miss something twice:

0.25 → 0.5 → 1.0 (capped)

At probability 1.0, this kanji is always accepted when randomly selected. It forces itself to the front of the line. You cannot escape it until you learn it.

The distribution self-organizes

Here is the key insight: you do not manually schedule anything. You do not set intervals. You do not decide what to study. The probability values create a distribution that automatically:

  • Oversamples what you do not know
  • Undersamples what you have mastered
  • Adapts to your personal learning speed
  • Maintains you in flow state

No two learners will have the same experience. The algorithm shapes itself to each person's individual strengths and weaknesses.

• • •

The Deep Insight: This Is Thermal Optimization

In February 2026, I sat down with Claude (Anthropic's AI assistant) to formalize what I had built thirty years earlier. What we discovered was remarkable: the K2 algorithm is mathematically equivalent to simulated annealing — a technique from physics used to find optimal configurations of complex systems.

Here is the analogy. When a blacksmith heats metal to reshape it, the atoms are vibrating wildly — everything is disordered, chaotic, "hot." As the metal cools, the atoms settle into an orderly crystalline structure. The cooling process, done right, produces the strongest possible material.

In K2:

  • High probability = "hot" kanji = you are struggling = needs frequent attention
  • Low probability = "cold" kanji = you have mastered it = can be left alone
  • Learning = the system "cooling" toward its ground state (everything mastered)

Each correct answer is like removing a tiny bit of heat from the system. The probability halving is equivalent to increasing what physicists call "competence energy" by a fixed amount (ln 2, if you want the math). Over time, the system cools. The distribution of attention becomes more and more focused on the items that still need work.

And the pool expansion rule? That is the equivalent of injecting energy to prevent premature freezing. When the system has cooled too much (everything mastered), you add a new "hot" kanji to keep the learning going.

The same mathematics that describes magnets cooling to their ground state describes a learner mastering a set of kanji. This is not a metaphor. It is the same equation:

P(select item) = e^(-competence)    # Boltzmann distribution

This is identical to:
P(state) = e^(-Energy / Temperature) # Statistical mechanics

I did not set out to build a thermal optimizer. I was just trying to learn kanji. But it turns out that effective learning and physical optimization share deep mathematical structure.

• • •

The Complete Algorithm in 50 Lines

One of the most satisfying things about K2 is its simplicity. The entire algorithm fits in about 50 lines of Python. No machine learning model. No neural network. No cloud dependency. Just elegant mathematics.

python
import random

class K2Learner:
    def __init__(self, items, p_init=0.5, threshold=0.2):
        self.all_items = items
        self.active = [items[0]]       # Start with one item
        self.p = {items[0]: p_init}    # Selection probabilities
        self.threshold = threshold
        self.p_init = p_init
        self.next_idx = 1

    def select_item(self):
        """Rejection sampling: pick randomly, accept based on p."""
        while True:
            item = random.choice(self.active)
            if random.random() < self.p[item]:
                return item
            # Rejected — try again

    def update(self, item, correct):
        """The entire update rule: halve or double."""
        if correct:
            self.p[item] /= 2          # Mastery: fade away
        else:
            self.p[item] = min(1.0, self.p[item] * 2)  # Struggle: come back

        # Auto-expand when current pool is mastered
        if max(self.p.values()) < self.threshold:
            if self.next_idx < len(self.all_items):
                new = self.all_items[self.next_idx]
                self.active.append(new)
                self.p[new] = self.p_init
                self.next_idx += 1

    def session(self, n_trials, test_func):
        """Run a learning session."""
        for _ in range(n_trials):
            item = self.select_item()
            correct = test_func(item)  # Returns True/False
            self.update(item, correct)

That is it. The select_item method uses rejection sampling to pick what to quiz. The update method adjusts probabilities and expands the pool. The session method runs a learning session.

Compare this to the thousands of lines of scheduling logic in systems like Anki or SuperMemo. K2 achieves adaptive spaced repetition through emergent dynamics rather than explicit rules.

• • •

How K2 Compares to Other Systems

Anki / SuperMemoDuolingoK2
SchedulingExplicit intervals ("review in 3 days")Strength meter decayImplicit via probability
State per itemInterval, ease factor, due date, historyStrength score, last seen, decay rateOne number (p)
Time trackingRequiredRequiredNot needed
Irregular practiceShows "overdue" cards, guilt-inducingStreak penalties, guilt mechanicsJust works — pick up where you left off
Flow stateNo (overdue backlog creates anxiety)No (streak guilt, gamification pressure)Yes (automatic difficulty calibration)
New materialManual additionFixed curriculumAuto-expansion when ready
Theoretical basisEbbinghaus forgetting curveProprietaryBoltzmann distribution / simulated annealing

The biggest difference is philosophical. Anki and Duolingo are scheduling systems — they decide when you should review each item. K2 is a selection system — it decides what to show you right now, based on your current state. This eliminates the concept of "overdue" items entirely. There is no guilt. There is no backlog. There is just the next kanji, chosen optimally for this moment.

• • •

The Formalization: February 2026

For thirty years, K2 existed as working code and a gut intuition about why it worked. In February 2026, I sat down with Claude and said: "I built this thing in 1995. It uses rejection sampling for spaced repetition. Can we formalize why it works?"

What followed was one of the most satisfying intellectual experiences of my life. Together, we worked through the mathematics and discovered that K2 sits at the intersection of several deep ideas:

  • Rejection sampling — the selection mechanism is a textbook Monte Carlo technique
  • Boltzmann distribution — the probability values follow the same distribution that governs thermal physics
  • Simulated annealing — learning is equivalent to a physical system cooling toward its ground state
  • Multi-armed bandits — the algorithm naturally balances exploration (trying new items) with exploitation (focusing on weak items)
  • Curriculum learning — the auto-expansion rule implements the same strategy used in modern machine learning

The formal paper — "Rejection Sampling for Adaptive Spaced Repetition: A Thermal Framework for Optimal Learning" — establishes these connections rigorously with proofs, theorems, and experimental results. But the core insight is simple: the same math that describes magnets cooling to their ground state describes a learner mastering a set of kanji.

• • •

Why Now? From 1995 to 2026

The K2 algorithm worked beautifully in 1995, but the technology had limitations. It was a desktop program. There was no way to test stroke order. Content had to be manually created. It was Japanese kanji only.

It is 2026. We have touch screens that capture stroke input. Mobile devices always in our pockets. And the same rejection sampling algorithm, proven over thirty years, now running in your browser.

K2 漢字 brings the original algorithm to the modern web with three study modes:

  • Meaning (意味) — See the kanji, recall its meaning
  • Reading (読み) — See the kanji, recall its pronunciation
  • Writing (書き) — See the meaning, recall the kanji

Each mode maintains its own independent probability for every kanji. You might recognize a character perfectly but struggle to recall its pronunciation — and the algorithm adapts to each dimension independently.

• • •

Questions

What is K2?

K2 is a spaced-repetition engine and the family of browser drill apps built on it, written by Erik Bethke in 1995 and formalized in 2026. Instead of scheduling reviews on a calendar, K2 gives every item a selection probability and chooses what to show you next by Monte Carlo rejection sampling. The same engine drives every K2 app: Japanese kanji, Chinese, Korean, Spanish, French, classical and medical Latin, Rubik's Cube algorithms, music theory, world geography and more.

How does the K2 algorithm work?

Every item in K2 carries a probability p, starting at 0.5. To choose what to ask next, K2 picks an item at random from the active pool, rolls a random number, and quizzes that item only if the roll comes in under its probability — otherwise it throws the item back and tries again. Answer correctly and p is halved; answer wrong and p is doubled. That is the entire update rule. There are no timestamps, no intervals, and no per-item scheduling state beyond p itself, which is why the whole engine is about fifty lines of code.

Does K2 use spaced repetition?

Yes, but K2 arrives at it from the opposite direction to most systems. Conventional spaced repetition is a scheduling system: it decides when each card is due. K2 is a selection system: it decides what to show you right now, given your current state. The spacing emerges from the probabilities rather than from a calendar — after three correct answers an item sits at p = 0.0625 and is rejected about 94% of the time it comes up. It is still in the pool and can resurface the moment you start missing it, but it costs you almost nothing. Because nothing is ever scheduled, K2 has no concept of an overdue item and no backlog to fall behind on.

How is K2 different from Anki?

Anki schedules each card with an interval from the SM-2 family of algorithms, and cards you miss pile up as an overdue queue. K2 stores one number per item and selects by rejection sampling, so nothing is ever due, nothing is overdue, and there is no backlog. K2 also expands its own pool: when the material you are working on has cooled, it adds a batch of new items on its own, instead of asking you to decide when to add more. The difference is philosophical as much as technical — Anki decides when you should review something, K2 decides what is worth your attention this second.

Why does K2 give me new material before I have finished the old?

That is K2 deliberately reheating the pool. K2 watches the items you are actively working on, and when their average probability has dropped far enough — meaning you have largely got them — it introduces a batch of new items at p = 0.5. This is automatic curriculum progression: you never decide when to move on, and K2 keeps you near the boundary where the work is hard enough to hold your attention but not so hard that it stops being possible. Struggle, and K2 stops expanding and lets you consolidate what you have.

Is K2 free?

Yes. Every K2 drill runs in your browser at no cost and with no account, and your progress is saved on your own device. Signing in with Bike4Mind is optional: it syncs your progress across devices, and the AI-generated reading and dialogue features then run on your own Bike4Mind credits. There is no paywall on the drills themselves.

• • •
漢字

Ready to experience it yourself?

700 kanji in 12 hours was not an anomaly. It is what happens when you remove friction and maintain perfect flow. The algorithm is ready. Your brain is ready. Let's go.

Start Learning Now
• • •