NonTraditional Lilypads

3 frogs are sitting on 3 of four lily pads in a line, leaving one unoccupied, as shown below:

A frog can only move to the empty lily pad either

  • by jumping to it if the frog is immediately next to the empty lily pad, or
  • by leaping over one frog if the frog is two seats away from the empty lily pad.

What is the least number of moves required in total for all the frogs to arrange themselves in the following configuration?


The answer is 6.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

7 solutions

Model the situation as an arrangement of the letters A B C ABC .

  • A jump does not change the arrangement of A B C ABC .

  • A leap results in swapping two neighboring letters. The empty leaf must be on either side of the two letters to be swapped. Thus A B C A C B A|BC| \mapsto A|CB| . (The vertical bar indicates the possible position of the empty leaf. After the leap, the vertical bar is in the other position: A B C A C B A|BC \mapsto ACB| and A B C A C B ABC| \mapsto A|CB .)

Since we wish to go from C B A CBA to A B C ABC , three leaps are needed at least:

C B A B C A B A C A B C or C B A C A B A C B A B C . CBA \mapsto BCA \mapsto BAC \mapsto ABC\ \ \ \text{or}\ \ \ CBA \mapsto CAB \mapsto ACB \mapsto ABC.

However, two leaps in a row has zero effect; e.g. A B C B A C A B C AB|C \mapsto |BAC \mapsto AB|C . We may therefore ignore solutions with two leaps in a row, and assume that every leap (except perhaps for the last) is followed by at least one simple jump. This results in at least five moves. Moreover, at any time at most one simple jump is needed to get the empty leaf in the right position for the next leap. Thus the shortest solution will be of the form (jump) - leap - jump - leap - jump - leap - (jumps) . \text{(jump) - leap - jump - leap - jump - leap - (jumps)}.

At this point we have proven that the solution consists of at least five steps.

If we skip the first jump, we start by swapping C B A C A B CBA \mapsto CAB , and the last swap will be A C B A B C ACB \mapsto ABC , leaving the empty leaf next to either B B or C C ; at least one additional jump is needed.

At this point we have proven that the solution consists of at least six steps.

We find a solution in six steps: C B A C A B C A B A C B A C B A B C A B C . CBA| \mapsto C|AB \mapsto |CAB \mapsto AC|B \mapsto ACB| \mapsto A|BC \mapsto |ABC. Alternatively, we can perform one jump at the beginning and follow the alternative route with C B A B C A CBA \mapsto BCA . In that case, it can be arranged that no jumps are needed at the end. This gives another solution in six steps: C B A C B A B C A B C A B A C B A C A B C . CBA| \mapsto CB|A \mapsto |BCA \mapsto B|CA \mapsto BAC| \mapsto BA|C \mapsto |ABC.

We have now shown that there are solutions with six steps.


I don't understand Rule 1 says: a frog can jump onto the empty pad by jumping to it if the frog is immediately next to the empty lily pad, So frog A jumps to the empty pad on its right leaving A pad empty. Now the 2nd rule says: a frog can jump onto the empty pad by leaping over one frog if the frog is two seats away from the empty lily pad. So frog C leaps over frog B and lands on pad A Giving the final needed configuration after only 2 jumps. Is it anything that I missed?

Luis Daselbe - 3 years, 10 months ago

Log in to reply

Your solution gets the empty lilypad in the correct positions, but the frogs are now out of order: B C A |BCA instead of A B C |ABC .

Arjen Vreugdenhil - 3 years, 10 months ago

The problem states a configuration CBA_ as the starting point to arrive at a configuration ABC. Getting to ABC can be done in 5 jumps _ABC requires 8 jumps.

John Cummings - 3 years, 10 months ago

Log in to reply

No; every configuration of frogs + empty leaf can be reached from any other configuration in seven steps or fewer.

start x y z x y z 1 x y z , y x z x y z , x y z , x z y 2 x y z , x z y , y x z , y x z x y z , x z y , y x z , y x z 3 x y z , x z y , y x z , y x z , y z x x z y , y x z , y x z , z x y 4 x z y , y z x , y z x , z x y x z y , z x y , y z x , y z x 5 x z y , z x y , z y x , z y x z x y , y z x , y z x , z y x 6 z x y , z y x , z y x z x y , z y x , z y x 7 z x y z y x \begin{array}{ccc} \text{start} & |xyz & x|yz \\ \hline 1 & x|yz,\,yx|z & |xyz,\,xy|z,\,xzy| \\ 2 & xy|z,\,xzy|,\,yxz|,\,y|xz & xyz|,\,xz|y,\,yx|z,\,|yxz \\ 3 & xyz|,\,xz|y,\,|yxz,\,y|xz,\,yzx| & x|zy,\,yxz|,\,y|xz,\,|zxy \\ 4 & x|zy,\,|yzx,\,yz|x,\,|zxy & |xzy,\,z|xy,\,y|zx,\,yzx| \\ 5 & |xzy,\,z|xy,\,zy|x,\,|zyx & zx|y,\,|yzx,\,yz|x,\,zyx| \\ 6 & zx|y,\,z|yx,\,zyx| & zxy|,\,zy|x,\,|zyx \\ 7 & zxy| & z|yx \\ \hline \end{array}

Arjen Vreugdenhil - 3 years, 10 months ago
Alex Li
Aug 7, 2017

To create a min bound for the solution, I will prove the minimum number of jumps and the minimum number of leaps separately.

First, I will prove the min. number of jumps. Notice that all frogs start an odd number of lily pads away from their final position, and that leaping over a frog moves them an even number of lily pads. We therefore find that each frog must jump at least once to reach it's destination, so the minimum number of jumps is 3 \boxed{3} .

Now, consider the minimum number of jumps. Each time a frog jumps, you switch positions of two adjacent frogs. It is easy to see that the quickest way to quickly sort the frogs CBA takes 3 \boxed{3} moves, so I will not bother making a more formal explanation.

Therefore, at best, we can solve this problem in 3 + 3 = 6 \boxed{6} moves.

This is possible by the method posted by Arjen.

C B A C B A B C A B C A B A C B A C A B C . CBA| \mapsto CB|A \mapsto |BCA \mapsto B|CA \mapsto BAC| \mapsto BA|C \mapsto |ABC.

We'll run breadth-first search (bfs) on this configuration space for the shortest solution:

(image taken shamelessly from Arjen's solution) (image taken shamelessly from Arjen's solution)

In this graph, each node represents a possible configuration of frogs and there is an edge if it is possible to go from one node to another in just one jump. Here is how we plan to explore this space:

  • Start at the initial configuration
  • Go to all possible configurations at distance 1 from this configuration.
  • From the last set of configurations reached, go ahead one more step, so as to reach all possible configurations at distance 2.
  • Repeat the last two steps until you reach the target configuration.

It is easy to see that this must indeed find the shortest distance between the start and the target configurations.


We encode the states as follows:

1
2
start = ([3, 2, 1, None], 3) # the empty lilypad is at position 4
goal = ([None, 1, 2, 3], 0)

and here is how we define the jumps:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
def jump(state):
    frogs, empty = state
    N = len(frogs)
    if empty > 0:
        new_state = frogs[:]
        new_state[empty], new_state[empty-1] = new_state[empty-1], new_state[empty]
        yield (new_state, empty-1)
    if empty > 1:
        new_state = frogs[:]
        new_state[empty], new_state[empty-2] = new_state[empty-2], new_state[empty]
        yield (new_state, empty-2)
    if empty < N-1:
        new_state = frogs[:]
        new_state[empty], new_state[empty+1] = new_state[empty+1], new_state[empty]
        yield (new_state, empty+1)
    if empty < N-2:
        new_state = frogs[:]
        new_state[empty], new_state[empty+2] = new_state[empty+2], new_state[empty]
        yield (new_state, empty+2)

and then, we implement the search:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def solve_frogs(start, goal):
    closed_set = set()
    open_queue = Queue()

    parents = {}

    open_queue.put(start)

    while not open_queue.empty():
        current_state = open_queue.get()
        closed_set.add(str(current_state))
        if current_state == goal:
            print "goal reached!"
            break
        for successor in jump(current_state):
            if str(successor) not in closed_set:
                open_queue.put(successor)
                parents[str(successor)] = current_state

    path = []
    state = goal
    while True:
        path.append(state)
        if state == start:
            break
        state = parents[str(state)]
    path.reverse()

    return path

And, finally to get the path:

1
2
3
4
5
6
7
8
9
path = []
state = goal
while True:
    path.append(state)
    if state == start:
        break
    state = parents[str(state)]
path.reverse()
print path

That gives

1
2
3
4
5
6
7
[([3, 2, 1, None], 3),
 ([3, None, 1, 2], 1),
 ([None, 3, 1, 2], 0),
 ([1, 3, None, 2], 2),
 ([1, 3, 2, None], 3),
 ([1, None, 2, 3], 1),
 ([None, 1, 2, 3], 0)]

Tarmo Taipale
Aug 7, 2017

Let pad 1 be the pad frog C C starts on, pad 2 be the pad frog B B starts on, pad 3 be the one pad frog A A starts on and pad 4 be the initially empty pad. We'll first show that at least 6 moves will be needed.

Let's present the positions of the frogs with letter arrangements(eg. the initial positions are C B A O CBAO , with the letter O O noting the empty pad.

Now, moving frog B B to pad 3 will take at least one move and moving frog A A to pad 2 will take at least one move. As frog C C can't go from pad 1 to pad 4 with only one move, moving frog C C will take at least two moves. These will take at least 4 moves total.

In addition, in the first move, either frog A A or frog B B must be moved to pad 4 as it's the only empty pad and frog C C can't be moved. Now we know at least 5 moves will be taken.

Finally, if frog C C is moved at least three times, at least 6 moves are now used. If frog C C is only moved twice, let's prove that either frog A A or frog B B will be moved onto pad 1, which would take a sixth move. Let's assume frog A A and frog B B are never moved onto pad 1. In that case, we have a situation where frog C C is on pad 2 or 3 and frogs A A and B B on pad 2 and 4 in either order, ie. O C A B OCAB , O A C B OACB , O C B A OCBA OR O B C A OBCA .At some point, the frog on pad 4 has to be moved (because neither frog A A nor B B is on pad 4 in the end). This is impossible before frog C C or the other frog on pad 2 or 3 is moved onto pad 1. If it was frog C C , it would now have been moved twice, and it would have to be moved at least once more as it's not on pad 4 where it will be in the end. This means, the other frog , which is either A A or B B , has to be moved onto pad 1 and we have proven by contradiction that a move will be taken to move either frog A A or frog B B on pad 1.

Now, let's prove we have a solution with 6 moves:

We find C B A O C B O A O B C A B O C A B A C O B A O C O A B C CBAO \mapsto CBOA \mapsto OBCA \mapsto BOCA \mapsto BACO \mapsto BAOC \mapsto OABC . This is a solution with 6 moves. Thus, the answer is 6 6 .

As per one can leap over another. It can be possible in 2 moves. Just move 2nd 🐸 from the left to the empty place and 1st 🐸 to the 2nd place from the left.

ritesh kumawat - 3 years, 10 months ago

Good job on showing that this is indeed the best we can do.

You might have noticed that reasoning about this problem analytically becomes harder when the number of frogs is larger. The reasoning in paragraph 4 is hard to follow through already.

I originally solved this problem by exhaustively listing out all the possiblities for 1,2,3,4,5,6 moves, in that order, using a computer.

Agnishom Chattopadhyay - 3 years, 10 months ago
Sam Salmons
Jul 29, 2017

My initial solution from July 29, 2017: Let = denote the blank lilypad. The starting configuration is: CBA= The following 6 steps get to the final position of =ABC:

  1. C=AB
  2. =CAB
  3. AC=B
  4. ACB=
  5. A=BC
  6. =ABC

Updated solution August 2, 2017: Per Calvin's suggestion, I'm adding a proof that 6 is the minimum by considering all possible states after 3 "useful" moves and then showing that at least 3 more steps are needed to get to the desired final state. Things to notice: (1) at step 1, there are only 2 moves (only A or B can move), (2) at each subsequent step there are only 2 "useful" moves because there are at most 3 moves (A, B, or C can move) but 1 of these moves undoes the move from the previous step. Thus, there are at most 8 possible states after 3 "useful" moves. With the same notation above and the minimum path bolded and parenthesis to indicate branch paths, the possible states after each useful move are:

  1. CB=A or C=AB
  2. (C=BA or =BCA) or ( =CAB or CA=B)
  3. ((=CBA or CAB=) or (B=CA)) or (( AC=B ) or (CAB= or =ACB)) - Note that 2 of the 8 states are missing because when the empty pad is on an end, there is only 2 possible moves and so only 1 of them is "useful". Also, 1 state, CAB=, is duplicated so there are only 5 cases.

Next, notice that a frog can only move either 1 or 2 spaces per step. Let's count how many steps are needed to get to the final state of =ABC for each of the 5 cases after step 3.

  1. For =CBA, A and C both need to move 2 spaces so we need at least 2 more steps, but from this configuration neither A nor C can do this on the next step so we need at least 3 more steps.
  2. For CAB=, C needs to move 3 spaces, so we need at least 2 more steps, but from this configuration C cannot move on the next step so we again need at least 3 more steps.
  3. For B=CA, A, B, and C each need to move so we need at least 3 more steps.
  4. For AC=B , again A, B, and C each need to move so at least 3 more steps.
  5. For CAB=, this is a duplicate of #2.
  6. For =ACB, B and C both need to move exactly 1 space so we need at least 2 more steps, but from this configuration, neither can move exactly 1 space on the next step so we need at least 3 more steps.

Having exhausted all possible cases, the minimum number of moves is 6.

How can we show that this is the minimum?

Calvin Lin Staff - 3 years, 10 months ago

Log in to reply

Not elegant but an exhaustive search can be done. At each step there are usually 2 moves and at most 3 possible moves so one could check somewhere between 32 and 243 configurations to see it can't be done in 5 or fewer moves. Honestly, I tried only a few cases and found most of my solutions required 7-12 steps so when I found something with 6, I figured it must be the min.

Sam Salmons - 3 years, 10 months ago

Log in to reply

Great! Thanks for sharing the details of how you approached this problem.

I wonder what the generalized result is.

Calvin Lin Staff - 3 years, 10 months ago

Log in to reply

@Calvin Lin Updated my solution to show that 6 is indeed the minimum for this configuration. Case work would be painful for generalizing this approach for every possible start and end configuration. If we limit ourselves to the specific problem of reversing a list of N frogs, a proof by induction or a recurrence relation could be set up that utilizes this result. For a list of 2 frogs: BA=, it requires 1 step to get to =AB. For a list of 3 frogs, we showed above 6 steps to go from CBA= to =ABC. For a list of 4 frogs, I have a solution with 12 steps, but I don't know whether it is minimum:

Overall, my approach with 3 frogs resembles the Tower of Hanoi problem, but in a somewhat directional manner: starting with 3 frogs to sort, steps 1-4 move the smallest frog (A) from right to left, step 5 moves the largest frog (C) from left to right, and then step 6 does cleanup.

If we started with 4 frogs: DCBA= and wanted to get to =ABCD, this approach needs 5 steps to get to DA=BC, but then I would not do cleanup on step 6. Instead, I would start moving D from left to right: 6. =ADBC 7. A=DBC 8. ABD=C 9. ABDC= 10. AB=CD 11. A=BCD 12. =ABCD

Sam Salmons - 3 years, 10 months ago

Log in to reply

@Sam Salmons Edit: On second thought, my comment did not make sense. I have removed it.

Calvin Lin Staff - 3 years, 10 months ago
Alkis Piskas
Aug 10, 2017

CBA_ -> C AB -> _CAB -> AC B -> ACB_ -> A_BC -> _ABC

All jumps over another letter to the right must be done by a "higher" ranked letter and all jumps over another letter to the left must be done by a "lower" ranked letter.

You have shown that 6 steps is possible. But can you do better than that?

Pi Han Goh - 3 years, 10 months ago
Mum Rmg
Aug 8, 2017

Initial position= CBAO where O is empty Lily pad 1.CBOA 2.OBCA 3.BOCA 4.BACO 5.BAOC 6.OABC

Is this the optimal strategy? Why?

Pi Han Goh - 3 years, 10 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...