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
What is the least number of moves required in total for all the frogs to arrange themselves in the following configuration?
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.
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?
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 instead of ∣ A B C .
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.
Log in to reply
No; every configuration of frogs + empty leaf can be reached from any other configuration in seven steps or fewer.
start 1 2 3 4 5 6 7 ∣ x y z x ∣ y z , y x ∣ z x y ∣ z , x z y ∣ , y x z ∣ , y ∣ x z x y z ∣ , x z ∣ y , ∣ y x z , y ∣ x z , y z x ∣ x ∣ z y , ∣ y z x , y z ∣ x , ∣ z x y ∣ x z y , z ∣ x y , z y ∣ x , ∣ z y x z x ∣ y , z ∣ y x , z y x ∣ z x y ∣ x ∣ y z ∣ x y z , x y ∣ z , x z y ∣ x y z ∣ , x z ∣ y , y x ∣ z , ∣ y x z x ∣ z y , y x z ∣ , y ∣ x z , ∣ z x y ∣ x z y , z ∣ x y , y ∣ z x , y z x ∣ z x ∣ y , ∣ y z x , y z ∣ x , z y x ∣ z x y ∣ , z y ∣ x , ∣ z y x z ∣ y x
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 .
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 moves, so I will not bother making a more formal explanation.
Therefore, at best, we can solve this problem in 3 + 3 = 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 .
We'll run breadth-first search (bfs) on this configuration space for the shortest 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:
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 |
|
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 |
|
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 |
|
And, finally to get the path:
1 2 3 4 5 6 7 8 9 |
|
That gives
1 2 3 4 5 6 7 |
|
Let pad 1 be the pad frog C starts on, pad 2 be the pad frog B starts on, pad 3 be the one pad frog 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 , with the letter O noting the empty pad.
Now, moving frog B to pad 3 will take at least one move and moving frog A to pad 2 will take at least one move. As frog C can't go from pad 1 to pad 4 with only one move, moving frog C will take at least two moves. These will take at least 4 moves total.
In addition, in the first move, either frog A or frog B must be moved to pad 4 as it's the only empty pad and frog C can't be moved. Now we know at least 5 moves will be taken.
Finally, if frog C is moved at least three times, at least 6 moves are now used. If frog C is only moved twice, let's prove that either frog A or frog B will be moved onto pad 1, which would take a sixth move. Let's assume frog A and frog B are never moved onto pad 1. In that case, we have a situation where frog C is on pad 2 or 3 and frogs A and B on pad 2 and 4 in either order, ie. O C A B , O A C B , O C B A OR O B C A .At some point, the frog on pad 4 has to be moved (because neither frog A nor B is on pad 4 in the end). This is impossible before frog C or the other frog on pad 2 or 3 is moved onto pad 1. If it was frog 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 or 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 or frog 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 . This is a solution with 6 moves. Thus, the answer is 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.
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.
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:
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:
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.
Having exhausted all possible cases, the minimum number of moves is 6.
How can we show that this is the minimum?
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.
Log in to reply
Great! Thanks for sharing the details of how you approached this problem.
I wonder what the generalized result is.
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
Log in to reply
@Sam Salmons – Edit: On second thought, my comment did not make sense. I have removed it.
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?
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?
Problem Loading...
Note Loading...
Set Loading...
Model the situation as an arrangement of the letters A B C .
A jump does not change the arrangement of A B C .
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 ∣ . (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 ∣ and A B C ∣ ↦ A ∣ C B .)
Since we wish to go from C B A to A B C , 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 .
However, two leaps in a row has zero effect; e.g. A B ∣ C ↦ ∣ B A C ↦ A B ∣ 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) .
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 , and the last swap will be A C B ↦ A B C , leaving the empty leaf next to either B or 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 . Alternatively, we can perform one jump at the beginning and follow the alternative route with C B A ↦ B C A . 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 .
We have now shown that there are solutions with six steps.