language ESSENCE' 1.0 given initial_grid : matrix indexed by [int(1..n),int(1..n)] of int(0,1) letting fig = flatten(initial_grid) letting spaces = (n * n) - sum(fig) find order : matrix indexed by [int(1..spaces)] of int(1..n*n) find moves : matrix indexed by [int(1..spaces-1)] of int(-1,1,-n,n) ifdef(`optimise_moves', `dnl find chdir : matrix indexed by [int(2..spaces-1)] of int(0,1) minimising sum(chdir) ')dnl such that ifdef(`optimise_moves', `dnl forAll i: int(2..spaces-1) . chdir[i] = 1 <-> moves[i-1] != moves[i], ')dnl allDiff(order), ifdef(`fill_all', `dnl forAll i: int(1..n*n) . fig[i] = 0 <-> exists j: int(1..spaces) . order[j] = i, ', `dnl forAll i: int(1..spaces) . fig[order[i]] != 1, ')dnl ifdef(`no_block_moves', `dnl forAll i: int(1..spaces-1) . fig[order[i] + moves[i]] != 1, ')dnl ifdef(`no_repeat_moves', `dnl forAll i: int(2..spaces-1) . forAll j: int(1..i-1) . order[i] + moves[i] != order[j], ')dnl forAll i: int(1..spaces-1) . order[i] + moves[i] = order[i+1], forAll i: int(1..spaces-1) . ifdef(`up_down_bounds', `dnl ((order[i] <= n) -> (moves[i] != -n)) /\ ((order[i] > n * n - n) -> (moves[i] != n)) /\ ')dnl ((order[i] % n = 1) -> (moves[i] != -1)) /\ ((order[i] % n = 0) -> (moves[i] != 1)) /\ true, ifdef(`opposite_move_check', `dnl forAll i: int(2..spaces-1) . moves[i] != -moves[i-1], ')dnl forAll i: int(2..spaces-1) . (moves[i] = moves[i-1]) \/ (fig[order[i] + moves[i-1]] = 1) \/ (exists j: int(1..i-1) . order[i] + moves[i-1] = order[j]) \/ (moves[i-1] = -n /\ order[i] <= n) \/ ifdef(`throw_exception', `dnl (moves[i-1] = n /\ order[i] > n * n - 1) \/ ', `dnl (moves[i-1] = n /\ order[i] > n * n - n) \/ ')dnl (moves[i-1] = -1 /\ order[i] % n = 1) \/ (moves[i-1] = 1 /\ order[i] % n = 0) \/ false, true