toh_enc.lp 523 B

12345678910111213141516171819
  1. % Generate
  2. { move(D,P,T) : disk(D), peg(P) } = 1 :- moves(M), T = 1..M.
  3. % Define
  4. move(D,T) :- move(D,_,T).
  5. on(D,P,0) :- init_on(D,P).
  6. on(D,P,T) :- move(D,P,T).
  7. on(D,P,T+1) :- on(D,P,T), not move(D,T+1), not moves(T).
  8. blocked(D-1,P,T+1) :- on(D,P,T), not moves(T).
  9. blocked(D-1,P,T) :- blocked(D,P,T), disk(D).
  10. % Test
  11. :- move(D,P,T), blocked(D-1,P,T).
  12. :- move(D,T), on(D,P,T-1), blocked(D,P,T).
  13. :- goal_on(D,P), not on(D,P,M), moves(M).
  14. :- { on(D,P,T) } != 1, disk(D), moves(M), T = 1..M.
  15. % Display
  16. #show move/3.