diff options
Diffstat (limited to 'src/grid-time.eprime')
| -rw-r--r-- | src/grid-time.eprime | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/grid-time.eprime b/src/grid-time.eprime new file mode 100644 index 0000000..251ed32 --- /dev/null +++ b/src/grid-time.eprime @@ -0,0 +1,97 @@ +language ESSENCE' 1.0 + +given initial_grid : matrix indexed by [int(1..n), int(1..n)] of int(0, 1) + +letting range be domain int(1..n) + +letting LEFT = 1 +letting RIGHT = 2 +letting UP = 3 +letting DOWN = 4 +letting BLOCK = 5 +letting END = 6 +letting SPACE = 0 + +letting map be domain int(SPACE, BLOCK) +letting directions be domain int(LEFT, RIGHT, UP, DOWN, END) +letting map_directions be domain map union directions + +letting dir_move be [-1, 1, -n, n] + +letting block_count = sum(flatten(initial_grid)) + +letting time_length be (n*n - block_count) +letting time_domain be int(1..time_length) + +letting grid_length be (n*n) +letting grid_domain be int(1..grid_length) + +find grid : matrix indexed by [grid_domain] of map_directions +find time : matrix indexed by [time_domain] of grid_domain +find time_ : matrix indexed by [int(1..(time_length-1))] of grid_domain +find full_grid : matrix indexed by [range, range] of map_directions + +such that + +$ redraw grid as full_grid +forAll x, y: range . + full_grid[x, y] = grid[(x-1)*n + y], + +forAll x: int(1..(time_length-1)) . + time_[x] = (time[x] + dir_move[grid[time[x]]]), + +$ blocks are in the same place +forAll x, y: range . + (initial_grid[x, y] = 1) <-> (grid[(y-1)*n + x] = BLOCK), + +$ there are no spaces in the answer +$ there are the same number of blocks in both grids +$ there is one end square +gcc(grid, [ SPACE, BLOCK, END ], [ 0, block_count, 1 ]), + +$ no square is visited twice +allDiff(time), + +$ no square visited is a block +forAll i: time_domain . + grid[time[i]] != BLOCK, + +$ no left-side squares can move left +forAll y: range . + grid[(y-1)*n + 1] != LEFT, + +$ no right-side squares can move right +forAll y: range . + grid[y*n] != RIGHT, + +$ no top-side squares can move up +forAll x: range . + grid[x] != UP, + +$ no bottom-side squares can move down +forAll x: range . + grid[n*(n-1) + x] != DOWN, + +$ squares point to the next square in time +forAll x: int(1..(time_length-1)) . + time[x] + dir_move[grid[time[x]]] = time[x + 1], + +$ squares cannot point "backwards" +forAll x: int(1..(time_length-1)) . + time[x] + time[x+1] != 0, + +$ squares cannot point into blocks +forAll x: int(1..(time_length-1)) . + grid[time_[x]] != BLOCK, + +$ the big boy +forAll x: int(1..(time_length-2)) . ( + (grid[time[x]] = grid[time_[x]]) \/ + (grid[time[x] + grid[time[x]] + grid[time[x]]] = BLOCK) \/ + (exists y: int(1..(x-1)) . y = (time[x] + grid[time[x]] + grid[time[x]])) \/ + ((grid[time[x]] = LEFT) /\ ((time[x] % n) = 1)) \/ + ((grid[time[x]] = RIGHT) /\ ((time[x] % n) = (n - 1))) \/ + ((grid[time[x]] = UP) /\ ((time[x]) <= (n + n))) \/ + ((grid[time[x]] = DOWN) /\ ((time[x]) >= (n * n - n - n))) ), + +true |
