Beautiful Matrix

Practice this coding question on Coding Gurukul.

Problem statement

A five-by-five panel contains exactly one illuminated cell. In one move, swap two adjacent rows or two adjacent columns. Find the fewest moves needed to bring the illuminated cell to the centre of the panel.

Input format

Five lines, each containing five integers.

Output format

Print the minimum move count.

Constraints

All entries are 0 or 1; exactly one entry is 1.

Sample input

1 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0

Sample output

4

Sign in to run or submit a solution in C++, Java or Python.