Skip to content
Tutorials Center
My learning

Topics

Lesson 50 of 63 ยท Real-World Projects

Project: A Training Plan Tracker

Build a practice tracker: log attempts, measure strength per topic, schedule reviews with spaced repetition and generate a daily plan of problems.

Most people improve at contests by solving many problems, but how they choose those problems matters just as much as how many they solve. A common failure is practicing only what already feels comfortable, or solving a hard problem once and never seeing the idea again. In this project you build a small training plan tracker that logs your attempts, finds weak topics, schedules reviews and proposes what to solve next.

The tracker is plain Python with no files or network, so it runs right here. It brings together dictionaries, sorting with custom keys (see sorting, events and sweeps) and a little scheduling logic. The ideas behind it, such as upsolving and filling topic gaps, are explained further in training plans and virtual contests.

What the tracker should do

Think about what a good coach would tell you each morning:

  1. "Here are the old problems you should revisit today, before you forget the idea."
  2. "Here is a new problem from your weakest topic, slightly harder than the hardest one you solved there."
  3. "Here is how you are doing per topic."

That gives us three features: a log of attempts, statistics per topic, and a plan generator. Spaced repetition decides which old problems come back.

flowchart LR
  L["Attempt log<br/>(day, problem, result)"] --> S["Per-topic statistics"]
  L --> R["Review schedule<br/>(boxes and due days)"]
  S --> P["Daily plan"]
  R --> P
  P --> L

The loop: results update statistics and the review schedule, which produce tomorrow's plan.

The data model

Each problem has an id, a topic and a difficulty rating (any number scale works; here it is the familiar Codeforces-style rating where 800 is easy and 2400 is very hard). An attempt has three possible results:

  • solved: you solved it on your own.
  • hint: you solved it only after reading a hint or an editorial.
  • failed: you did not solve it.

Days are plain integers (day 1, day 2, and so on). Using integers keeps the code deterministic and easy to test. If you later want real dates, datetime.date supports the same arithmetic (date + timedelta(days=3)).

Step 1: statistics per topic

The simplest useful statistic is how many attempts succeeded in each topic and the hardest problem solved. A dictionary of small dictionaries does it.

Python Attempt log and per-topic statistics

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The table shows that DP has the lowest rate (2 of 4) even though its hardest solved problem is 1300. The dictionary LOG is also the single source of truth: statistics are derived from it, never edited by hand. Keeping raw events and computing summaries from them is a habit worth having, because you can later add new statistics without losing data.

A raw success rate is shaky with few attempts: one lucky solve gives 100%. Later we use a smoothed rate, (solved + 1) / (tried + 2), which starts at 50% for a topic you have never tried and moves toward the real rate as evidence grows.

Step 2: spaced repetition

People forget ideas on a predictable curve, and reviewing just before you would forget is the most efficient way to keep them. Spaced repetition does this with growing gaps between reviews. We use five boxes with these gaps in days:

INTERVALS = [1, 3, 7, 14, 30]

Every problem sits in a box. The rules after each attempt are simple:

  • solved: move up one box (capped at the last), so the next review is further away.
  • hint: stay in the same box. You needed help, so the idea is not yet yours.
  • failed: go back to box 0 and review tomorrow.

The next review day is day + INTERVALS[box].

Python The review schedule of one problem

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Read the table row by row. A failure on day 1 means a review on day 2. Two clean solves later the problem sits in box 2 with a gap of a week. The hint on day 12 does not move it, so the next review is the same 7 days later. The failure on day 22 drops it to box 0, and the problem has to climb again.

You will notice this schedule has no cleverness about why you failed. A failure caused by a silly typo and a failure caused by a missing idea are treated the same. If you want more nuance, add a fourth result such as slip that keeps the box unchanged.

Step 3: the planner

Now combine everything into a Tracker. It owns the log-derived state and offers four methods:

  • record(day, problem, result) updates statistics, the box and the due day.
  • reviews(day) lists problems whose due day has arrived, oldest first.
  • new_problem(topic) picks a never-seen problem in that topic. It targets a difficulty about 100 above the hardest problem you solved there, because practice is most effective just beyond your comfort zone, and it ignores anything more than 400 above, which would mostly cost time.
  • plan(day) takes up to two reviews and fills the remaining slots with new problems from the weakest topics.

Topics are sorted by smoothed strength, weakest first, with the topic name as a tie-breaker so the output is deterministic.

Python Tracker with a daily plan

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

On day 7 the plan has two reviews (min-coins and sum-pairs, both due since day 4) and one new DP problem, because DP has the lowest smoothed strength. The simulated learner then solves everything, and the schedule moves on. On day 8 the failed bitmask-tour returns as a review, which is exactly the point of box 0.

Look at days 9 and 10: only two items. The planner found no suitable new problem, because every untouched problem was either already seen or too far above the current level. The planner stays quiet instead of inventing work, and in real use that is your cue to add more problems to PROBLEMS or to raise the 400 limit.

Reading the numbers

Statistics are only useful if they change what you do. A few rules of thumb:

  • Weak topic, not weak day. Judge a topic by at least five or six attempts before concluding anything.
  • Growth edge. If the hardest solved rating in a topic stays flat for weeks while attempts pile up, you are practicing below your level or you are stuck on a missing technique. Study the technique, then return.
  • Review debt. If len(tr.reviews(day)) keeps growing, you add new problems faster than you review. Cut new problems until the debt is gone.
  • Hints are data. A topic with many hint results is nearly as weak as one with failures, even if the solve rate looks fine.

Ideas to extend it

  • Persistence. Save the log to a file as JSON lines and rebuild the tracker at startup. Because all state is derived from the log, nothing else has to be saved.
  • Time spent. Add minutes to each attempt and report the average time per solved problem per topic.
  • Contest mode. Add a contest entry type with a rank or score, and chart progress over time.
  • Better scheduling. Replace the fixed boxes by an ease factor per problem, as flashcard programs do.
  • Tests. Check the planner with small hand-made histories, the same way stress testing checks algorithms.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why does the tracker derive statistics from the raw log instead of editing counters by hand?

    Events are the source of truth. Any summary can be recomputed from them, while hand-edited counters can drift and cannot be extended.
  2. 2. A problem is in box 2 (gap 7 days) and you solve it only after reading a hint. What happens to its box?

    A hint means the idea is not yet fully yours, so the box stays the same and the review comes after the same gap.
  3. 3. Why use the smoothed rate (solved + 1) / (tried + 2) to compare topics?

    With no attempts the rate is 50%, and a few attempts move it only gradually. Raw rates from tiny samples are misleading.
  4. 4. The planner returned no new problem on day 9. What is the most likely reason?

    new_problem only offers unseen problems up to 400 rating points above the hardest solved in that topic. If none remain, it returns None and the planner adds nothing.

Summary

  • A training tracker is a log of attempts plus derived statistics, a review schedule and a planner.
  • Spaced repetition moves a problem to a longer gap after each solve, keeps it after a hint and resets it after a failure.
  • A smoothed success rate compares topics fairly even with few attempts.
  • The planner mixes due reviews with new problems slightly above your level in your weakest topics.
  • Because state is derived from the log, saving the log is enough to persist everything.
  • Use the numbers to change behavior: study missing techniques, clear review debt and add problems when the pool runs out.

Next: Practice: Warm-Up Problems with Solutions