Ferry

Logic Level 2

The goal is to design an algorithm that will take the lists (12345678, XY) and convert them to (87654321, XY). The algorithm must move elements in the following manner:

  • Select exactly two consecutive elements from the first list.
  • Without changing their order, exchange those elements with the two elements in the second list.

What is the least number of moves required by the algorithm?


Hint: The 13 steps below, even though non-optimal, show how to accomplish the job following the rules. So, your answer must be smaller than 13.

[Step 00] 1 2 3 4 5 6 7 8 (X Y)
[Step 01] 1 2 3 4 5 6 X Y (7 8)
[Step 02] 7 8 3 4 5 6 X Y (1 2)
[Step 03] 7 1 2 4 5 6 X Y (8 3)
[Step 04] 8 3 2 4 5 6 X Y (7 1)
[Step 05] 8 7 1 4 5 6 X Y (3 2)
[Step 06] 8 7 1 4 5 3 2 Y (6 X)
[Step 07] 8 7 6 X 5 3 2 Y (1 4)
[Step 08] 8 7 6 X 1 4 2 Y (5 3)
[Step 09] 8 7 6 5 3 4 2 Y (X 1)
[Step 10] 8 7 6 5 3 X 1 Y (4 2)
[Step 11] 8 7 6 5 4 2 1 Y (3 X)
[Step 12] 8 7 6 5 4 3 X Y (2 1)
[Step 13] 8 7 6 5 4 3 2 1 (X Y)

×

Problem Loading...

Note Loading...

Set Loading...