The testing Sudokus must be fairly simple, as more complex puzzles (with fewer clues) lead to more possible solutions.
The solutions are enumerated in nondeterministic way (because of random_permutation/2
on line 256), so it is better to have only one solution to avoid excessive backtracking during the testing.
Tip: While testing, feel free to use the "Copy" button in upper right corner of the code blocks!
((Sudoku = [
[2,4,3,1,6,_],
[3,1,6,5,2,_],
[6,5,2,4,3,1],
[4,2,_,3,5,6],
[_,_,5,6,4,2],
[5,_,4,2,1,_]],
solveSudoku(3,2,Sudoku),
Sudoku =
[[2,4,3,1,6,5],
[3,1,6,5,2,4],
[6,5,2,4,3,1],
[4,2,1,3,5,6],
[1,3,5,6,4,2],
[5,6,4,2,1,3]], !,
writeln('Test #1 passed!'));
writeln('Test #1 failed!')).
((Sudoku = [
[5,3,_,_,7,_,_,_,_],
[6,_,_,1,9,5,_,_,_],
[_,9,8,_,_,_,_,6,_],
[8,_,_,_,6,_,_,_,3],
[4,_,_,8,_,3,_,_,1],
[7,_,_,_,2,_,_,_,6],
[_,6,_,_,_,_,2,8,_],
[_,_,_,4,1,9,_,_,5],
[_,_,_,_,8,_,_,7,9]],
solveSudoku(3,3,Sudoku),
Sudoku =
[[5,3,4,6,7,8,9,1,2],
[6,7,2,1,9,5,3,4,8],
[1,9,8,3,4,2,5,6,7],
[8,5,9,7,6,1,4,2,3],
[4,2,6,8,5,3,7,9,1],
[7,1,3,9,2,4,8,5,6],
[9,6,1,5,3,7,2,8,4],
[2,8,7,4,1,9,6,3,5],
[3,4,5,2,8,6,1,7,9]], !,
writeln('Test #2 passed!'));
writeln('Test #2 failed!')).
((Sudoku = [
[9,15,_,11,14,16,_,4,5,1,6,10,7,_,3,12],
[14,16,_,4,9,_,2,11,7,8,3,12,5,1,6,10],
[5,1,_,10,7,_,3,12,9,15,2,11,14,16,_,4],
[7,8,_,_,5,1,_,10,14,16,_,4,9,15,_,_],
[15,9,11,2,16,14,4,13,1,5,_,6,8,7,12,3],
[16,14,4,13,15,9,11,2,8,7,_,3,1,5,10,_],
[1,5,10,6,8,7,12,3,_,9,11,2,16,_,4,13],
[_,7,12,3,1,5,10,_,16,14,4,_,15,9,11,2],
[2,11,9,_,13,4,_,16,6,10,5,_,_,12,7,8],
[_,4,14,16,2,_,9,15,3,12,7,8,6,_,5,1],
[6,10,5,1,3,12,7,8,2,11,9,15,13,_,14,_],
[3,12,7,8,_,10,5,1,13,4,14,16,2,11,9,_],
[11,2,15,_,4,13,16,_,10,_,1,5,_,3,8,7],
[4,_,16,14,11,_,15,9,12,3,8,7,10,6,1,5],
[10,_,1,5,12,3,8,_,11,2,15,9,4,13,16,14],
[12,3,8,7,10,6,_,5,4,13,16,14,11,2,15,_]],
solveSudoku(4,4,Sudoku),
Sudoku =
[[9,15,2,11,14,16,13,4,5,1,6,10,7,8,3,12],
[14,16,13,4,9,15,2,11,7,8,3,12,5,1,6,10],
[5,1,6,10,7,8,3,12,9,15,2,11,14,16,13,4],
[7,8,3,12,5,1,6,10,14,16,13,4,9,15,2,11],
[15,9,11,2,16,14,4,13,1,5,10,6,8,7,12,3],
[16,14,4,13,15,9,11,2,8,7,12,3,1,5,10,6],
[1,5,10,6,8,7,12,3,15,9,11,2,16,14,4,13],
[8,7,12,3,1,5,10,6,16,14,4,13,15,9,11,2],
[2,11,9,15,13,4,14,16,6,10,5,1,3,12,7,8],
[13,4,14,16,2,11,9,15,3,12,7,8,6,10,5,1],
[6,10,5,1,3,12,7,8,2,11,9,15,13,4,14,16],
[3,12,7,8,6,10,5,1,13,4,14,16,2,11,9,15],
[11,2,15,9,4,13,16,14,10,6,1,5,12,3,8,7],
[4,13,16,14,11,2,15,9,12,3,8,7,10,6,1,5],
[10,6,1,5,12,3,8,7,11,2,15,9,4,13,16,14],
[12,3,8,7,10,6,1,5,4,13,16,14,11,2,15,9]], !,
writeln('Test #3 passed!'));
writeln('Test #3 failed!')).
((generateSudoku(9,9,3,3,0.5,Sudoku),
solveSudoku(3,3,Sudoku),!,
writeln('Test #4 passed!'));
writeln('Test #4 failed!')).