Skip to content

Instantly share code, notes, and snippets.

@royling
Last active August 29, 2015 13:57
Show Gist options
  • Save royling/9736912 to your computer and use it in GitHub Desktop.
Save royling/9736912 to your computer and use it in GitHub Desktop.
sudoku: check if a guess is valid or not
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
@royling
Copy link
Author

royling commented Apr 5, 2014

Run coffee script:

$ npm install -g coffee-script
$ coffee sudoku.coffee

Run ES6 version via traceur:

$ npm install -g traceur
$ traceur --experimental sudoku_es6.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment