Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
54 lines (48 sloc) 1.27 KB
% Solver for puzzles like in game Logo: Part 1
% http://www.worldofspectrum.org/infoseekid.cgi?id=0011860
%
% Author: Sergey Dymchenko <kit1980@gmail.com>
%
% Picat 1.9#2 - http://picat-lang.org
import planner.
import util.
prev('.') = '.'.
prev('2') = '1'.
prev('3') = '2'.
prev('4') = '3'.
prev('1') = '4'.
final(Board) =>
MaxR = Board.length(),
MaxC = Board[1].length(),
foreach (R in 1..MaxR, C in 1..MaxC)
Board[R, C] == '.'
end.
action(Board, NewBoard, Action, Cost) =>
MaxR = Board.length(),
MaxC = Board[1].length(),
between(1, MaxR, R),
between(1, MaxC, C),
Board[R, C] == '1',
NewBoard = copy_term(Board),
NewBoard[R, C] := '.',
foreach ((DR, DC) in [(0, 1), (0, -1), (1, 0), (-1, 0)])
NR = R + DR, NC = C + DC,
if (NR > 0, NR <= MaxR, NC > 0, NC <= MaxC) then
NewBoard[NR, NC] := prev(NewBoard[NR, NC])
end
end,
Action = (R, C),
Cost = 1.
main =>
MaxR = read_int(), MaxC = read_int(),
Board = new_array(MaxR, MaxC),
foreach (R in 1..MaxR)
Line = read_line(),
foreach (C in 1..MaxC)
Board[R, C] = Line[C]
end
end,
plan_unbounded(Board, PlanRev),
foreach ((R, C) in reverse(PlanRev))
printf("%d %d%n", R, C)
end.