Last active
August 29, 2015 13:57
-
-
Save royling/9736912 to your computer and use it in GitHub Desktop.
sudoku: check if a guess is valid or not
This file contains hidden or 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
validGuess = (sudoku, x, y, value) -> | |
row = sudoku[y] | |
column = row[x] for row in sudoku | |
cube = (sudoku[~~(y/3) + i][~~(x/3) + j] for i in [0..2] for j in [0..2]).reduce (result, curr) -> result.concat(curr) | |
value not in [].concat row, column, cube | |
guess = (sudoku, x, y, value) -> | |
sudoku[y][x] = value if validGuess sudoku, x, y, value | |
# sudoku = genValidSudoku() | |
# sudoku[~~(i/9)][i%9] = 0 for i in [0...81] | |
# guess sudoku, 6, 3, 2 | |
# console.log sudoku |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run coffee script:
Run ES6 version via
traceur
: