Problem 2484. BLOCK x3 (Version 3)
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
-
Select every other element of a vector
35575 Solvers
-
2529 Solvers
-
927 Solvers
-
Return unique values without sorting
985 Solvers
-
128 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!