Simple solution to the problem showed in https://neil.fraser.name/news/2013/03/16/ The goal is to find the number of enclosed areas in a grid made of diagonal lines.
The program reads the maze from the standard input. The first line read must be the dimension of the maze, and the following lines are the maze cells, made of /
(or 0
) and \
(or 1
).
No enclosed areas:
./maze
2,2
\\
\\
#..#...
.#..#..
..#..#.
#..#..#
.#..#..
..#..#.
...#..#
number of enclosed areas = 0
One enclosed area:
./maze
3,3
//\
\\/
/\\
...#..#...
..#..#.#..
.#..#...#.
#..#.....#
.#..#...#.
..#..#.#..
...#..#...
..#.#..#..
.#...#..#.
#.....#..#
6, 1
number of enclosed areas = 1
More:
./maze
5,5
/\/\\
\/\//
\\\\\
/////
\\///
...#.....#..#...
..#.#...#.#..#..
.#...#.#...#..#.
#.....#.....#..#
.#...#.#...#..#.
..#.#...#.#..#..
#..#..#..#..#...
.#..#..#..#..#..
..#..#..#..#..#.
...#..#..#..#..#
..#..#..#..#..#.
.#..#..#..#..#..
#..#..#..#..#..#
.#..#...#..#..#.
..#..#.#..#..#..
...#..#..#..#...
number of enclosed areas = 3