diff options
| author | Tom Harley | 2020-01-23 13:03:25 +0000 |
|---|---|---|
| committer | Tom Harley | 2020-01-23 13:03:25 +0000 |
| commit | f3d375722130e448802c046af2d75f66a06de498 (patch) | |
| tree | 0c82bd620be0401c6b9ba69c3314dfe0d9522eae /src/superfluous.eprime | |
| download | machinarium-f3d375722130e448802c046af2d75f66a06de498.tar.gz machinarium-f3d375722130e448802c046af2d75f66a06de498.zip | |
Diffstat (limited to 'src/superfluous.eprime')
| -rw-r--r-- | src/superfluous.eprime | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/src/superfluous.eprime b/src/superfluous.eprime new file mode 100644 index 0000000..4f1ad2a --- /dev/null +++ b/src/superfluous.eprime @@ -0,0 +1,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 |
