The Control Rod Cooling Problem

The hexagonal array of cells shown below show the relative locations of control rods in a nuclear power plant. The arrows between the cells show the direction of coolant between the cells. Due to the accumulation of heat in the coolant it is important to know the distance between any two cells along the directions of flow of the coolant. You have been assigned the task of generating a function that will return the shortest distance between any pair of cells counting as one (1) the distance between adjacent cells.

A cell is identified by a pair of numbers indicating its row and column. The columns of cells are vertical but the rows are slanted up from left to right. For example the top cell is in row 0 and column 5. Your task is to create a function that returns an integer representing the minimal distance between a pair of cells defined by their row,col labels.

min_cell_distance(row1,col1,row2,col2)

Where row1,col1 is the source cell and row2,col2 is the destination cell. If either of the row, col pairs do not represent a valid cell your function should return -1. Submit your source code and distances for the following example cell pairs as computed by your function.

from (1,3) to (5,7) from (3,0) to (8,10)

from (3,1) to (7,5) from (5,5) to (3,5)

from (5,7) to (1,3) from (10,5) to (0,5)

from (7,5) to (3,1) from (10,10) to (0,5)