Skip to content

Instantly share code, notes, and snippets.

@tuzz tuzz/sudoku.snt
Created Nov 10, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.