An extension to problems 2451 (by me) and 2478 (by Rifat Ahmed).
Always based on the android game BLOCK x3. The objective is to align the 1's in the matrix (7x7) using minimum movements. The valid movements are horizontal and vertical (by one step). A zero (0) indicates an empty space.
Your task is to count minimum number of movements required to align the FOUR 1's vertically or horizontally (it was only 3 blocks in problem 2451).
Beware to align the 4 blocks WITHOUT aligning 3 blocks before
Example:

- [0 0 0 0 0 0 0;
- 0 0 0 1 0 0 0;
- 0 0 0 0 1 0 0;
- 0 0 0 1 0 0 0;
- 0 0 0 0 1 0 0;
- 0 0 0 0 0 0 0;
- 0 0 0 0 0 0 0]
If you move the second 1 to the left, you align 3 blocks and loose because the last 1 remains alone. But if you begin by the first (to the right) and after the third (to the right), you win. Note that there exist multiple solutions. (you can also move the blocks n°4 to the left and n°2 to the left).
So here Output = 2;
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers9
Suggested Problems
-
Find the peak 3n+1 sequence value
2565 Solvers
-
314 Solvers
-
161 Solvers
-
Convert hex color specification to MATLAB RGB
254 Solvers
-
Are all the three given point in the same line?
600 Solvers
More from this Author43
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!