Video 2, chapter 4

Frogs and Toads

How the frogs and toads puzzle is solved, how a counting argument of jumps and slides gives a lower bound, and why a legal route then proves that the minimum number of moves for three of each is 15.

  • Video 2, chapter 4
  • See what cannot change

Seven stones lie in a row with the middle one empty. Three frogs stand on the left three stones facing right, and three toads stand on the right three stones facing left. Each animal may only move forward, either by sliding onto the empty stone in front of it or by jumping over one animal of the other kind onto the empty stone just beyond. Can the frogs and the toads swap sides, and what is the smallest number of moves that does it? This page counts what every solution must contain, which shows that any solution takes exactly 15 moves, and then gives a route that does it in 15.

Key terms

Frogs and toads puzzle

Definition The frogs and toads puzzle with nn animals of each kind, where n≥1n \ge 1, uses a row of 2n+12n + 1 stones numbered from left to right. At the start, nn frogs stand on stones 11 to nn, nn toads stand on stones n+2n + 2 to 2n+12n + 1, and stone n+1n + 1 is empty. Each stone holds at most one animal, so exactly one stone is empty at every moment. Frogs only ever move to the right and toads only to the left, one animal per move. A move is either a slide, in which an animal moves onto the empty stone directly in front of it, or a jump, in which an animal passes over the stone directly in front of it, which must hold an animal of the other kind, and lands on the empty stone just beyond. Nobody moves backward, jumps over an animal of its own kind or jumps over more than one stone. Any animal with a legal move may make it, so frogs and toads do not have to take turns. The goal is to have toads on stones 11 to nn, frogs on stones n+2n + 2 to 2n+12n + 1 and stone n+1n + 1 empty again. The puzzle can be solved for every nn, and every solution contains exactly n2n^2 jumps and 2n2n slides, so every solution has

n2+2n=(n+1)2−1n^2 + 2n = (n + 1)^2 - 1

moves. Some sequences of legal moves get stuck before reaching the goal, so a solution still has to be planned.

In plain words Frogs hop right, toads hop left, and nobody turns back. Every frog has to get past every toad, and the only way to get past is to jump. All solutions have the same length, but a careless move can leave every animal blocked.

Example Write F for a frog, T for a toad and □\square for the empty stone. With one of each kind the row is F □ T\mathrm{F\,\square\,T}. The frog slides, the toad jumps over it, and the frog slides again, which gives □ F T\mathrm{\square\,F\,T}, then T F □\mathrm{T\,F\,\square}, then T □ F\mathrm{T\,\square\,F}. That is 3=12+2⋅13 = 1^2 + 2 \cdot 1 moves. With two of each kind, the eight moves in the table solve the puzzle.

MoveWhat happensStones 1 to 5 after the move
1The frog on stone 2 slides to stone 3F □ F T T\mathrm{F\,\square\,F\,T\,T}
2The toad on stone 4 jumps to stone 2F T F □ T\mathrm{F\,T\,F\,\square\,T}
3The toad on stone 5 slides to stone 4F T F T □\mathrm{F\,T\,F\,T\,\square}
4The frog on stone 3 jumps to stone 5F T □ T F\mathrm{F\,T\,\square\,T\,F}
5The frog on stone 1 jumps to stone 3□ T F T F\mathrm{\square\,T\,F\,T\,F}
6The toad on stone 2 slides to stone 1T □ F T F\mathrm{T\,\square\,F\,T\,F}
7The toad on stone 4 jumps to stone 2T T F □ F\mathrm{T\,T\,F\,\square\,F}
8The frog on stone 3 slides to stone 4T T □ F F\mathrm{T\,T\,\square\,F\,F}

There are four jumps and four slides, and 8=22+2⋅28 = 2^2 + 2 \cdot 2. If instead both frogs slide at the start, the row becomes □ F F T T\mathrm{\square\,F\,F\,T\,T} and no animal can move, because the empty stone is behind both frogs and more than two stones ahead of each toad.

Counting argument

Definition A counting argument proves a fact about every solution of a puzzle at once by keeping count of some quantity. One chooses a quantity whose values at the start and at the goal are known and finds exactly how much each kind of move can change it. Every solution has to change the quantity by the full difference, which limits how many moves of each kind it can contain. The argument covers all solutions, including ones nobody has written down, but it does not show that a solution exists.

In plain words Instead of trying routes one after another, keep score of something that has to change between the start and the goal, and ask how much a single move can change it.

Example In the frogs and toads puzzle with nn of each kind, pair every frog with every toad, which gives n⋅n=n2n \cdot n = n^2 pairs. At the start the frog of each pair is to the left of its toad, and at the goal it is to the right. A slide passes nobody, so it changes the order of no pair. A jump passes exactly one animal of the other kind, so it reverses the order of exactly one pair. A frog that has passed a toad can never fall behind it again, because frogs only move right and toads only move left. So each pair is reversed exactly once, and every solution has exactly n2n^2 jumps.

Now count distance. Frogs never pass one another, so the frog that starts on stone kk ends on stone k+n+1k + n + 1, and the frogs travel n(n+1)n(n + 1) stones in all. The toads travel the same distance to the left, so all the animals together travel 2n(n+1)2n(n + 1) stones. A slide covers one stone and a jump covers two, so a solution with SS slides satisfies

2n2+S=2n(n+1),2n^2 + S = 2n(n + 1),

which gives S=2nS = 2n. For three of each kind there are 99 pairs, so 99 jumps, and 2424 stones of travel. The jumps cover 1818 of them, which leaves 66 slides and 1515 moves in total.

Lower bound

Definition A lower bound for a quantity is a number that the quantity is proved never to be less than. A lower bound LL for the number of moves in a puzzle means that every solution uses at least LL moves. It does not claim that a solution exists, and it does not claim that some solution uses exactly LL moves. A lower bound that the quantity actually reaches is called sharp.

In plain words A lower bound rules out doing better than some number. It does not promise that anyone can do that well.

Example For three of each kind, each count on its own gives a lower bound. The animals must travel 2424 stones and no move covers more than 22, so every solution has at least 1212 moves. Nine pairs must be reversed and no move reverses more than one, so every solution has at least 99 moves. Both statements are true, but neither bound is sharp, because no solution has 99 or 1212 moves. Combining the two counts gives the bound of 1515, since the 99 jumps cover only 1818 of the 2424 stones and the remaining 66 stones need 66 slides. That bound is sharp, as the route of 1515 moves below shows.

Minimum number of moves

Definition The minimum number of moves of a puzzle is the smallest number of moves among all its solutions. It exists only when the puzzle has at least one solution. Proving that the minimum is MM takes two facts, a lower bound showing that no solution uses fewer than MM moves, and a construction, which is a legal solution that uses exactly MM moves. For the frogs and toads puzzle with nn of each kind the minimum is n2+2nn^2 + 2n. In this puzzle every solution has that length, so the minimum is also the only possible length.

In plain words A count can show how short a solution would have to be, but only an actual route shows that such a solution is there to be found.

Example For three of each kind, start from F F F □ T T T\mathrm{F\,F\,F\,\square\,T\,T\,T} and let the two kinds move in runs, first the frogs, then the toads, and so on, with 1,2,3,3,3,21, 2, 3, 3, 3, 2 and 11 moves in the runs. At every move of a run, the kind whose turn it is has exactly one legal move, so the runs fix the route.

RunWho movesMovesStones 1 to 7 after the run
1frogsslideF F □ F T T T\mathrm{F\,F\,\square\,F\,T\,T\,T}
2toadsjump, slideF F T F T □ T\mathrm{F\,F\,T\,F\,T\,\square\,T}
3frogsjump, jump, slide□ F T F T F T\mathrm{\square\,F\,T\,F\,T\,F\,T}
4toadsjump, jump, jumpT F T F T F □\mathrm{T\,F\,T\,F\,T\,F\,\square}
5frogsslide, jump, jumpT □ T F T F F\mathrm{T\,\square\,T\,F\,T\,F\,F}
6toadsslide, jumpT T T F □ F F\mathrm{T\,T\,T\,F\,\square\,F\,F}
7frogsslideT T T □ F F F\mathrm{T\,T\,T\,\square\,F\,F\,F}

The route has 99 jumps and 66 slides, so it meets the lower bound of 1515, and 1515 is the minimum. In the middle of the route the empty stone sits at the far left with the animals alternating, and three toad jumps in a row carry it to the far right. The same pattern of runs, 1,2,…,n1, 2, \dots, n, then nn twice more, then n−1n - 1 down to 11, solves the puzzle for every nn. Its length is

n(n+1)2+2n+n(n−1)2=n2+2n.\begin{aligned} &\frac{n(n + 1)}{2} + 2n + \frac{n(n - 1)}{2} \\[0.4em] &\quad = n^2 + 2n. \end{aligned}

Check yourself

  1. Four frogs and four toads stand on nine stones with the middle stone empty. How many jumps, slides and moves does a solution have, and do runs of 1,2,3,4,4,4,3,21, 2, 3, 4, 4, 4, 3, 2 and 11 moves have the right total?
Show the answer

There are 4⋅4=164 \cdot 4 = 16 frog and toad pairs, so a solution has 1616 jumps. Each frog ends 55 stones to the right of where it started, so the frogs travel 2020 stones, and the toads travel another 2020 to the left. The jumps cover 3232 of these 4040 stones, which leaves 88 slides. A solution therefore has

16+8=2416 + 8 = 24

moves, in agreement with 42+2⋅4=244^2 + 2 \cdot 4 = 24 and with (4+1)2−1=24(4 + 1)^2 - 1 = 24. The runs add up to 1+2+3+4+4+4+3+2+1=241 + 2 + 3 + 4 + 4 + 4 + 3 + 2 + 1 = 24, as they should.

  1. Change the rules so that an animal may also move backward, by sliding back onto the empty stone directly behind it or by jumping back over one animal of the other kind. Jumping over an animal of the same kind is still forbidden. With three of each kind, is 1515 still the minimum, and does every solution still have 1515 moves?
Show the answer

The minimum is still 1515, but solutions can now be longer. Count forward and backward moves separately, with jfj_f and jbj_b forward and backward jumps and sfs_f and sbs_b forward and backward slides. Call a pair finished when its frog is to the right of its toad. A forward jump finishes one pair and a backward jump undoes one, while slides change no pair, and the number of finished pairs goes from 00 to 99. So jf−jb=9j_f - j_b = 9. Measured in each animal’s forward direction, the animals still have to travel 2424 stones in net, so 2(jf−jb)+(sf−sb)=242(j_f - j_b) + (s_f - s_b) = 24, which gives sf−sb=6s_f - s_b = 6. The number of moves is then

jf+jb+sf+sb=15+2(jb+sb).\begin{aligned} &j_f + j_b + s_f + s_b \\[0.4em] &\quad = 15 + 2(j_b + s_b). \end{aligned}

Every solution therefore has at least 1515 moves, and the old route of 1515 moves is still legal, so 1515 is still the minimum. Backward moves only add to the count. For example, the frog on stone 33 can slide forward to stone 44 and straight back, and the old route then takes 1515 more moves, for 1717 in all. The counting argument still gives a sharp lower bound, but it no longer fixes the length of every solution.

  1. Extend the puzzle to unequal groups. Three frogs stand on stones 11 to 33, stone 44 is empty, and two toads stand on stones 55 and 66. The goal is toads on stones 11 and 22, stone 33 empty and frogs on stones 44 to 66. Count the jumps, slides and moves, find a route, and give the count for mm frogs and nn toads.
Show the answer

There are 3⋅2=63 \cdot 2 = 6 frog and toad pairs, so a solution has 66 jumps. The frog that starts on stone kk ends on stone k+3k + 3, so the frogs travel 3⋅3=93 \cdot 3 = 9 stones, and the toad that starts on stone kk ends on stone k−4k - 4, so the toads travel 2⋅4=82 \cdot 4 = 8 stones. The jumps cover 1212 of the 1717 stones, which leaves 55 slides and 1111 moves.

One route uses runs of 1,2,3,2,21, 2, 3, 2, 2 and 11 moves, starting with the frogs. The frog on stone 33 slides. The toads jump and slide. The frogs jump, jump and slide, which gives □ F T F T F\mathrm{\square\,F\,T\,F\,T\,F}. The toads jump twice, the frogs slide and jump, and a toad slides, which ends at T T □ F F F\mathrm{T\,T\,\square\,F\,F\,F} after 1111 moves.

With mm frogs and nn toads there are mnmn jumps. The frogs travel m(n+1)m(n + 1) stones and the toads n(m+1)n(m + 1), so the slides number m(n+1)+n(m+1)−2mn=m+nm(n + 1) + n(m + 1) - 2mn = m + n. The number of moves is

mn+m+n=(m+1)(n+1)−1,\begin{aligned} &mn + m + n \\[0.4em] &\quad = (m + 1)(n + 1) - 1, \end{aligned}

which is 1111 for three frogs and two toads and n2+2nn^2 + 2n when m=nm = n.