This challenge is based off of Flow Free. An online version can be found here: http://www.moh97.us/
You will be given a puzzle, and you must return 1
if the puzzle is solvable, or 0
if it is not.
To solve a puzzle, the player must create a path to connect each pair of numbers using every empty square exactly once.
You are passed in the dimensions of the square, and then the x,y,c (where c is a number representing the color) of each dot. For example:
If 5,5
0,0,0
3,0,1
1,1,2
1,2,2
4,2,1
4,4,0
was passed to you, it would represent:
0..1.
.2...
.2..1
....0
And should return 1.
Here are some more test problems:
5,2
2,0,1
0,1,2
4,1,2
represents:
..1..
2...2
and is not solvable because there is only 1 1
.
4,2
0,0,0
3,0,0
0,1,0
3,1,0
represents:
0..0
0..0
and is not solvable because it includes more than 2 0
s.
8,6
0,0,1
7,5,1
represents:
1.......
........
........
........
........
.......1
and is not solvable (as you can't use every square).
2,5
0,0,1
2,0,6
4,0,6
0,1,4
3,1,4
4,1,1
represents:
1.6.6
4..41
and is not solvable because you cannot connect the 1s.
6,3
1,0,4
5,0,1
0,1,4
1,1,3
5,1,3
0,2,2
3,2,2
5,2,1
represents:
.4...1
43...3
2..2.1
and is not solvable because you cannot connect the 1s (or the 3s), as the two paths must necessarily cross.
5,2
0,0,1
3,0,1
0,1,3
4,1,1
represents:
1..1.
3...3
and is not solvable because you cannot use all of the squares in building a path.
2,2
0,0,0
1,1,0
represents:
1.
.1
and is not solvable because you can't use all of the squares here either
Here are some more tests:
5,5
0,3,0
0,4,1
1,2,2
1,3,1
2,0,0
3,0,4
3,1,2
3,3,5
3,4,4
4,4,5
should return 1
13,13
1,1,0
9,1,1
10,1,2
11,1,3
1,2,4
2,2,5
5,2,6
7,2,7
3,3,0
5,4,6
6,4,1
9,6,3
4,7,8
5,8,9
12,8,8
11,9,10
2,10,4
4,10,2
9,10,5
11,10,7
1,11,9
12,12,10
should return 1
7,7
0,0,0
0,1,1
1,1,2
2,1,3
4,2,4
0,3,1
5,3,3
0,4,4
2,4,5
5,4,2
0,5,0
1,5,5
3,5,6
3,7,6
should return 0
This is a code golf, and the standard rules apply.
1
if any one of them visits all cells and connects all terminals. Obviously this approach wouldn't complete in a reasonable amount of time for anything but the smallestN
(number of empty cells), but we still have a mathematical guarantee that the algorithm would eventually return the correct value. \$\endgroup\$