Last active
July 27, 2016 16:37
-
-
Save megawac/3c82089929d404bbf72834d5471c7435 to your computer and use it in GitHub Desktop.
rough sudo code for emkay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkSquare(matrix, i, j) { | |
return columnValid(matrix, i) && rowValid(matrix, j) | |
} | |
function solvePuzzle(boardMatrix) { | |
(i, j) = selectFirstUnfilled(boardMatrix) | |
matrix = boardMatrix.clone() | |
matrix[i, j] = red | |
if (checkSquare(matrix, i, j)) { | |
try { | |
return solvePuzzle(matrix) | |
} catch() { | |
// do nothing, just continue the and try to solve with blue | |
} | |
} | |
matrix[i, j] = blue | |
if (checkSquare(matrix, i, j)) { | |
return solvePuzzle(matrix) | |
} else { | |
throw 'Board unsolvable' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment