← HomeAll tools
Interactive Lesson · Heads & Legs

Chickens & Rabbits: How Many of Each?

X heads, Y legs — skip the algebra for now. Guess first, and the answer surfaces itself

Step 1 · The question
The cage holds 12 heads and 40 legs. How many chickens and rabbits?
Start at "0 rabbits", check how far the legs are off, then swap chickens for rabbits one by one.
Heads 12 heads
Legs 40 legs
Rabbits 0 rabbits

How to play

The cage holds 12 heads and 40 legs. Don't set up equations yet. Drag the "Rabbits" slider from 0: every extra rabbit turns one chicken into a rabbit, and the total leg count rises by exactly 2. Watch the leg-count chip — the moment it says "exact", you have your answer.

Every guess lands in the attempt log on the right; click any entry to jump back to that guess. Too lazy to drag? Hit "Auto-enumerate" and the lesson walks through every guess for you.

Think first, then open

Before you drag anything, answer three questions in your head. Stuck? That's fine — drag a couple of times and it starts to click.

  1. If all 12 were chickens, how many legs would that be? How far from 40?
  2. Swap 1 chicken for 1 rabbit — how many legs does that add? Why?
  3. How many swaps does it take to close that gap?
Thought about it? Open to compare

All chickens gives 2 × 12 = 24 legs — 16 short of 40. Each rabbit adds 2, so it takes 16 ÷ 2 = 8 swaps: 8 rabbits and 4 chickens. You probably hit it on your 8th guess too.

What enumeration reveals

With g rabbits there are 12 − g chickens, so the legs total 2×(12−g) + 4×g = 24 + 2g. Each swap adds exactly 2 legs — which is why "short by 16 legs" means exactly 8 swaps. The leg column in the attempt log is really a straight line.

The one-step shortcut

Open the derivation (try it yourself first)

Once you've enumerated a few times, compress it: assume all 12 are chickens. That predicts 24 legs — 16 short of the real 40. Each rabbit adds 2, so rabbits = (40 − 24) ÷ 2 = 8, chickens = 12 − 8 = 4. The formula lands exactly where your trial-and-error did.

In general: rabbits = (legs − 2 × heads) ÷ 2, chickens = heads − rabbits. Change the puzzle and the two methods always agree.

Try it

  • Set 35 heads and 94 legs (the original puzzle from the ancient Chinese classic Sunzi Suanjing): how many attempts until the hit?
  • Set legs to 24 (all-chicken legs): what did the answer become?
  • 10 heads, 30 legs: which outnumber which this time, and why?

FAQ

Why must the leg count be even?
Chickens have 2 legs and rabbits have 4, so any mix gives an even total. If a puzzle hands you an odd number, it has no chicken-rabbit solution — whatever you counted, it probably wasn't a chicken or a rabbit.
Enumerating is slow. Any faster guessing?
Yes. Since each swap changes the legs by exactly 2, you can jump several at once: short 10 legs? Swap 5 chickens. That's the seed of the algebraic shortcut — the attempt log shows the leg count is a straight line, and straight lines can be finished in one step.
How does this relate to equations?
Let x be the rabbits: 2H + 2x = F is exactly the formula above as an equation. Enumeration sees the line; algebra computes it. Both roads reach the same answer.
Is anything uploaded?
No. Drawing and math happen entirely in your browser; the page makes no network requests and needs no account. Your comments stay in your own browser too.

Tool: Heads and Legs explorer. Chinese version: 鸡兔同笼探究课件. Also try the phone plan comparison lesson.