Created
February 13, 2012 14:20
-
-
Save athos/1817230 to your computer and use it in GitHub Desktop.
Sudoku(4x4) solver in Alloy
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
sig Digit {} | |
one sig One, Two, Three, Four extends Digit {} | |
sig Cell {content: one One + Two + Three + Four} | |
sig Group { | |
cells: set Cell | |
} { | |
no disj c, c': cells | c.content = c'.content | |
} | |
sig Row, Column, Matrix extends Group {} | |
one sig | |
Ca0, Ca1, Ca2, Ca3, | |
Cb0, Cb1, Cb2, Cb3, | |
Cc0, Cc1, Cc2, Cc3, | |
Cd0, Cd1, Cd2, Cd3 extends Cell {} | |
one sig Ra, Rb, Rc, Rd extends Row {} | |
one sig C0, C1, C2, C3 extends Column {} | |
one sig Ma0, Ma2, Mc0, Mc2 extends Matrix {} | |
fact { | |
Ra.cells = Ca0 + Ca1 + Ca2 + Ca3 | |
Rb.cells = Cb0 + Cb1 + Cb2 + Cb3 | |
Rc.cells = Cc0 + Cc1 + Cc2 + Cc3 | |
Rd.cells = Cd0 + Cd1 + Cd2 + Cd3 | |
C0.cells = Ca0 + Cb0 + Cc0 + Cd0 | |
C1.cells = Ca1 + Cb1 + Cc1 + Cd1 | |
C2.cells = Ca2 + Cb2 + Cc2 + Cd2 | |
C3.cells = Ca3 + Cb3 + Cc3 + Cd3 | |
Ma0.cells = Ca0 + Ca1 + Cb0 + Cb1 | |
Ma2.cells = Ca2 + Ca3 + Cb2 + Cb3 | |
Mc0.cells = Cc0 + Cc1 + Cd0 + Cd1 | |
Mc2.cells = Cc2 + Cc3 + Cd2 + Cd3 | |
} | |
// 1 2 * * | |
// 3 4 1 * | |
// * 1 * * | |
// * * * 1 | |
fact { | |
Ca0.content = One | |
Ca1.content = Two | |
Cb0.content = Three | |
Cb1.content = Four | |
Cb2.content = One | |
Cc1.content = One | |
Cd3.content = One | |
} | |
pred show {} | |
run show for 20 but 16 Cell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment