Created
February 22, 2015 21:34
-
-
Save kim0/cffc9676a6e9098f44bb to your computer and use it in GitHub Desktop.
3_coin.mzn
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
% include "globals.mzn"; | |
int: n = 3; | |
int: num_moves = 3; % first row is the init move | |
array[0..num_moves,1..n] of var bool: x; | |
array[1..n] of bool: init = [true,false,true]; % Initial state | |
array[1..num_moves] of var 1..num_moves: ops_seq; % The sequence of flips to solution | |
array[1..n,1..n] of bool: operations = [|false, false, true | false, true, false| true, false, false|]; % true means flip bit | |
% Constraints | |
constraint forall(j in 1..n) (x[0,j]=init[j]); | |
constraint forall(i in 1..num_moves, j in 1..n) (x[i,j] = x[i-1,j] xor operations[ops_seq[i],j]); | |
constraint forall(j in 1..n)(x[num_moves,j] == [false, false, false][j]) \/ % \/ means Victory condition ;) | |
forall(j in 1..n)(x[num_moves,j] == [true, true, true ][j]); | |
solve satisfy; | |
output[ | |
if j = 1 then "\n" else " " endif ++ | |
show(x[m,j]) | |
| m in 0..num_moves, j in 1..n | |
] ++ | |
["\n"]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment