In memory of Tim Peters · 1952–2026

Can you out-sort Timsort?

Every time your phone, your browser or a Python script sorts a list, it is probably running the algorithm Tim Peters wrote in 2002. Here's your chance to beat it. Weigh zen stones two at a time on a balance and find their order in fewer weighings than Python's list.sort() needs on exactly the same stones.

How it works
  • 16 gardens
  • 12 data shapes
  • 1 very good algorithm

The gardens

Stars: 0 / 48 · ★ sorted · ★★ tied Tim · ★★★ beat Tim (or hit the unbeatable minimum)

Loading gardens…

Free play: any size, any shape

How it works

⚖️ One weighing = one comparison

A sorting algorithm never sees the numbers it sorts. It can only ask "is this one less than that one?" Your balance works the same way. The stones look alike; only weighing reveals the order.

🧠 Free deductions

If A is lighter than B and B is lighter than C, you never need to weigh A against C. The game tracks everything you can deduce. Each stone shows the ranks it could still have, and it settles once its place is certain.

🐍 The opponent is real

"Tim" is the exact comparison sequence CPython's classic list.sort() runs on your stones. For short lists that's a run check (count_run) plus binary insertion, as Tim Peters wrote it. The Lab shows the full algorithm with galloping merges.

📜 Read the story

Timsort is fast because real data has structure. Each garden tells you something about its stones. Python doesn't get to read the story, so you can beat it by using what it can't know.

Open the Timsort Lab → Take the Zen of Python quiz →