DWITE Online Computer Programming Contest

Ice Maze

January 2010
Problem 5

Yes, it’s a maze, but it’s one of those fancy puzzle mazes where there is no friction on the floor and one must bump into walls to stop.

You will start at a point of interest, and must traverse to the next point in alphabetical order. You may only travel in straight lines, and will continue to slide until there is a # wall directly in front of the path. Once stopped, you can push off in any of the four directions. Assume that the maze’s boundary is surrounded by walls.

The objective is to stop at the target, not simply slide through it.

For example, this travels from A to stop at B in 13 steps. Note that arrows are to illustrate the shortest path, and will not actually be in the data file.

A>>>#
###v#
^>>B#
<<<v#
...##

The input file DATA5.txt will contain a single 10×10 maze as described above.

The output file OUT5.txt will contain 5 integers, the distance travelled from starting at a point of interest to stopping at the next. That is, the pairs A–B, B–C, C–D, D–E, E–F.

Sample Input:
A....E...B
..........
..........
..........
..........
..........
F.........
#.........
......#...
.....D...C
Sample Output:
9
9
16
9
11