3e0f9b8a
Francisco Coelho
back to work?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#const moves=15.
% instance
peg(a;b;c).
disk(1..4).
init_on(1..4, a).
goal_on(1..4, c).% generating
1 { move(D, P, T) : disk(D) : peg(P) } 1 :- T = 1..moves.
% defining
move(D, T) :- move(D, _, T).
on(D, P, 0) :- init_on(D, P).
on(D, P, T) :- move(D, P, T).
on(D, P, T + 1) :- on(D, P, T), not move D(T + 1), T < moves.
blocked(D - 1, P, T + 1) :- on(D, P, T), T < moves.
blocked(D - 1, P, T) :- blocked(D, P, T), disk(D).
% testing
:- move(D, P, T), blocked(D - 1, P, T).
:- move(D, T), on(D, P, T - 1), blocked(D, P, T).
:- not 1 { on(D, P, T) } 1, disk(D), T = 1..moves.
:- goal_on(D, P), not on(D, P, moves).
% displaying
#hide
#show move/3
|