Problem 44709. Toads and Frogs Puzzle
On a one-dimensional board with n + m + 1 cells, there are n counters in the first n cells representing Toads and m counters in the last m cells representing Frogs. The empty cell is represented by X. For illustration, if n = 4 and m = 3, then the problem is as depicted below:
T T T T X F F F
Toads and Frogs take turns moving. Moves consist of sliding a Toad or Frog into the empty cell or jumping over one opposing creature into the empty cell. (Toads cannot jump over themselves and neither can Frogs.) Toads can only move rightward and Frogs can only move leftward.
What is the total number of moves (i.e. jumps and slides) required for the toads to switch their positions with the frogs as depicted below:
F F F X T T T T
ALGORITHM: To solve the problem, whenever there is a choice between a slide and a jump, the jump must be made.
ILLUSTRATION: Consider n = 2 toads and m = 1 frog, then the algorithm could proceed as follows:
T T X F T X T F Slide T F T X Jump T F X T Slide X F T T Jump F X T T Slide
Hence, a total of five moves is required for n = 2 toads and m = 1 frog.
Solution Stats
Problem Comments
-
1 Comment
Your description of the game is at odds with your example. In particular, you write that "Toads and Frogs take turns moving", but in your example, in the 3rd and 4th moves, the toads move twice in a row.
Perhaps this is because there is no valid move for the frogs after the third move. However, when moves are skipped when there is no valid move, the game will generally end in unwinnable situations where neither frogs nor toads can make further progress.
Finally, you say that "whenever there is a choice between a slide and a jump, the jump must be made". Assuming that this only refers to the player whose turn it is, this isn't possible: if it's (say) the toads' turn, then a jump is only possible if the board looks like [ ... T F X ... ], and no slide is then possible.
It would be nice if you could clarify what rules are actually supposed to be used for the game.
Solution Comments
Show commentsProblem Recent Solvers18
Suggested Problems
-
190 Solvers
-
553 Solvers
-
410 Solvers
-
159 Solvers
-
Find the next Fibonacci number
565 Solvers
More from this Author18
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!