# Encoding toh_decision.gringo

Name toh_decision.gringo [Root]    Unclassified (114) Martin Gebser Martin Gebser and Roland Kaminski A Gringo encoding of the Towers-of-Hanoi problem. 2009-03-12 21:38 2009-05-11 19:26 TowersOfHanoiCompetition disk/1on0/2ongoal/2steps/1time/1 put/3 No #hide. #show put/3. % choose a disk to move 1 { move(T,Y) : disk(Y) : Y > 3 } 1 :- time(T), not steps(T). :- move(T,Y), blocked(T,Y). % choose a location 1 { put(T,X) : disk(X;X+1) } 1 :- time(T), not steps(T). :- put(T,X), blocked(T,X), not null(T). :- put(T,X), move(T,Y), Y <= X. % place disks on(0,X,Y) :- on0(X,Y). on(T+1,X,Y) :- on(T,X,Y), disk(X;Y), X < Y, time(T), not move(T,Y), not steps(T). on(T+1,X,Y) :- put(T,X,Y). % blocked disks blocked(T,X) :- disk(X;Y), on(T,X,Y), X < Y. % convert output put(T,X,Y) :- put(T,X), move(T,Y), X < Y. % check goal conditions goal(T) :- on(T,X,Y) : ongoal(X,Y), time(T). :- steps(T), not goal(T). % :- steps(T), not on(T,X,Y), ongoal(X,Y). % constrain redundant moves null(T) :- put(T,X,Y), on(T,X,Y), X < Y. :- move(T-1;T,Y), not null(T). :- null(T), not goal(T). % :- move(T-1;T,Y).