Skip to content

Instantly share code, notes, and snippets.

@tuzz
Created November 10, 2016 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuzz/7534bb2dad961b15966e661b33797163 to your computer and use it in GitHub Desktop.
Save tuzz/7534bb2dad961b15966e661b33797163 to your computer and use it in GitHub Desktop.
My canonical solution for solving a Sudoku in Sentient
function main () {
array9<array9<int5>> sudoku;
sudoku.each(function (row) {
invariant row.uniq?;
invariant row.all?(function (n) {
return n.between?(1, 9);
});
});
sudoku.transpose.each(function (column) {
invariant column.uniq?;
});
sudoku.boxes.each(function (box) {
invariant box.uniq?;
});
expose sudoku;
};
function boxes (sudoku) {
boxes = [];
3.times(function^ (i) {
3.times(function^ (j) {
boxes.push(sudoku.box(i, j));
});
});
return boxes;
};
function box (sudoku, i, j) {
cells = [];
x = i * 3;
y = j * 3;
3.times(function^ (i) {
3.times(function^ (j) {
cells = cells.push(sudoku[x + i][y + j]);
});
});
return cells;
};
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment