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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
member(X,[X|_]).
member(X,[_|Y]):-
member(X,Y).
append([],L,L).
append([X|A],B,[X|C]):-
append(A,B,C).
efface(A,[A|L],L):-
!.
efface(A,[B|L],[B|M]):-
efface(A,L,M).
efface(_,[],[]).
nol(N):-
read(N).
input(_,_,N,N,L,L).
input(X,Y,R,N,L,O):-
read(X),
read(Y),
append([[X,Y]],L,M),
C IS R+1,
input(_,_,C,N,M,O).
enter(L):-
nol(N),
input(X,Y,0,N,[],L).
searchnext(X,Y,[H|T]):-
H=[X,Y];
H=[Y,X];
searchnext(X,Y,T).
onemove(_,_,[],L):-
write(L).
onemove(X,Y,L,H):-
searchnext(X,Y,L),
efface([X,Y],L,N),
L<>N,
write(N),elan(line),
append(H,[Y],F),
onemove(Y,Z,N,F).
onemove(X,Y,L,H):-
searchnext(X,Y,L),
efface([Y,X],L,N),
L<>N,
write(N),elan(line),
append(H,[Y],F),
onemove(Y,Z,N,F).
go:-
enter(L),!,
onemove(X,Y,L,[X]).
|