1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
language ESSENCE' 1.0
letting SPACE = 0
letting BLOCK = 1
letting initial_grid_domain be int(SPACE, BLOCK)
given initial_grid :
matrix indexed by [int(1..n), int(1..n)] of initial_grid_domain
letting block_count = sum(flatten(initial_grid))
letting total_moves = n * n - block_count
letting moves_domain be domain int(1..total_moves)
letting grid_side be domain int(1..n)
letting LEFT = 2
letting RIGHT = 3
letting UP = 4
letting DOWN = 5
letting dirs be domain int(LEFT, RIGHT, UP, DOWN)
letting dir_x = [ -1, 1, 0, 0 ; dirs]
letting dir_y = [ 0, 0, -1, 1 ; dirs]
letting opp_dir = [ RIGHT, LEFT, DOWN, UP ; dirs ]
letting END = 6
letting solution_domain be domain initial_grid_domain union dirs union int(END)
find solution :
matrix indexed by [moves_domain, grid_side, grid_side] of solution_domain
find final_grid : matrix indexed by [grid_side, grid_side] of solution_domain
find moved_to :
matrix indexed by [int(2..total_moves), grid_side, grid_side]
of solution_domain
such that
forAll t: int(2..total_moves) .
forAll x, y: grid_side .
( (solution[t, x, y] = LEFT)
\/ (solution[t, x, y] = RIGHT)
\/ (solution[t, x, y] = UP)
\/ (solution[t, x, y] = DOWN) ) ->
(moved_to[t, x, y] = solution[t, x + dir_x[solution[t, x, y]], y + dir_y[solution[t, x, y]]]),
$ all steps have a move moving into the end (except at the start)
forAll t: int(2..total_moves) .
exists x, y: grid_side .
moved_to[t, x, y] = END,
$ final_grid is just the last step in the solution
forAll x, y: grid_side .
solution[total_moves, x, y] = final_grid[x, y],
$ initial_grid is the same as the first step in the solution, except for end
forAll x, y: grid_side .
(solution[1, x, y] = END) \/ (solution[1, x, y] = initial_grid[x, y]),
$ blocks are in the same place for all iterations of the grid
forAll t: moves_domain .
forAll x, y: grid_side .
(initial_grid[x, y] = BLOCK) <-> (solution[t, x, y] = BLOCK),
$ there is an end spot in every step
forAll t: moves_domain .
gcc(flatten(solution[t, .., ..]), [ END ], [ 1 ]),
$ the final iteration of the solution has no spaces
forAll x, y: grid_side .
final_grid[x, y] != SPACE,
$ moves are preserved across steps
forAll t: int(2..total_moves) .
forAll x, y: grid_side .
( (solution[t-1, x, y] = LEFT)
\/ (solution[t-1, x, y] = RIGHT)
\/ (solution[t-1, x, y] = UP)
\/ (solution[t-1, x, y] = DOWN) ) ->
(solution[t, x, y] = solution[t-1, x, y]),
$ you gotta move
forAll t: int(2..total_moves) .
forAll x, y: grid_side .
(solution[t-1, x, y] = END) ->
( (solution[t, x, y] = LEFT)
\/ (solution[t, x, y] = RIGHT)
\/ (solution[t, x, y] = UP)
\/ (solution[t, x, y] = DOWN)
\/ (solution[t, x, y] = END) ),
$ all squares that change change to the same thing (except the end)
forAll t: int(2..total_moves) .
forAll x, y: grid_side .
(solution[t-1, x, y] != solution[t, x, y]) ->
(forAll x_, y_: grid_side .
(solution[t, x, y] = END) \/
(solution[t, x_, y_] = END) \/
(solution[t, x_, y_] = solution[t, x, y]) \/
(solution[t, x_, y_] = solution[t-1, x_, y_]) ),
$ spaces are preserved
forAll t: int(2..total_moves) .
forAll x, y: grid_side .
(solution[t-1, x, y] = SPACE) ->
((solution[t, x, y] = SPACE) \/ (solution[t, x, y] = END)),
$ moves cannot go "off the edge"
forAll t: moves_domain .
forAll x, y: grid_side .
( (solution[t, x, y] = LEFT)
\/ (solution[t, x, y] = RIGHT)
\/ (solution[t, x, y] = UP)
\/ (solution[t, x, y] = DOWN) ) ->
( ((x + dir_x[solution[t, x, y]]) >= 1)
/\ ((x + dir_x[solution[t, x, y]]) <= n)
/\ ((y + dir_y[solution[t, x, y]]) >= 1)
/\ ((y + dir_y[solution[t, x, y]]) <= n) ),
$ moves cannot move into space
$ moves cannot move into blocks
forAll t: int(2..total_moves) .
forAll x, y: grid_side .
( (solution[t, x, y] = LEFT)
\/ (solution[t, x, y] = RIGHT)
\/ (solution[t, x, y] = UP)
\/ (solution[t, x, y] = DOWN) ) ->
( (solution[t, x + dir_x[solution[t, x, y]],
y + dir_y[solution[t, x, y]]] != SPACE)
/\ (solution[t, x + dir_x[solution[t, x, y]],
y + dir_y[solution[t, x, y]]] != BLOCK)
/\ (solution[t, x + dir_x[solution[t, x, y]],
y + dir_y[solution[t, x, y]]] != opp_dir[solution[t, x, y]])),
$ either the x or y coordinate of the end block stays the same
forAll t: int(2..total_moves) .
exists x, y: grid_side .
(solution[t-1, x, y] = END) /\
((exists x_: grid_side . solution[t, x_, y] = END) \/
(exists y_: grid_side . solution[t, x, y_] = END)),
true
|