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 60 61 62 63 64 65
| % premier element d'une liste
first(X,L):-
L =[X|_].
% second élément
second(X,L):-
L=[_|Y],first(X,Y).
% on remplit le premier
isnext1(L2,L1):-
second(X,L1),
L2=[3,X].
% on remplit le second
isnext2(L2,L1):-
first(X,L1),
L2=[X,5].
% on vide le premier dans le second si c'est possible
isnext3(L2,L1):-
first(X,L1),
second(Y,L1),
X+Y<6,
Z is X+Y,
L2=[0,Z].
% on vide le second dans le premier si c'est possible
isnext4(L2,L1):-
first(X,L1),
second(Y,L1),
X+Y<4,
Z is X+Y,
L2=[Z,0].
% on fait déborder le grand avec le petit
isnext5(L2,L1):-
first(X,L1),
second(Y,L1),
X+Y>4,
Z is X+Y-5,
L2=[Z,5].
% on fait déborder le petit avec le grand
isnext6(L2,L1):-
first(X,L1),
second(Y,L1),
X+Y>2,
Z is Y+X-3,
L2=[3,Z].
isnext(L2,L1):-
isnext1(L2,L1);
isnext2(L2,L1);
isnext3(L2,L1);
isnext4(L2,L1);
isnext5(L2,L1);
isnext6(L2,L1).
comesfrom(L3,L1):-
isnext(L3,L1);
comesfrom(L2,L1),
isnext(L3,L2). |