This repository has been archived on 2026-03-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
TP-PL/TP7.pl
Super_JK 00cec73a26 ajout TP
2022-06-05 15:44:11 +02:00

50 lines
1.0 KiB
Prolog

:- use_module(library(clpfd)).
magique3(C):-
length(C,9),
C ins 1..9,
all_distinct(C),
contraintes(C),
label(C).
contraintes(C):-
C = [C11,C12,C13,C21,C22,C23,C31,C32,C33],
SL1 #= C11+C12+C13,
SL1 #= C21+C22+C23,
SL1 #= C31+C32+C33,
SL1 #= C11+C21+C31,
SL1 #= C12+C22+C32,
SL1 #= C13+C23+C33,
SL1 #= C11+C22+C33,
SL1 #= C13+C22+C31.
machine(T,P,L,R) :-
L = [E2,E1,C50,C20,C10],
R = [R2,R1,R50,R20,R10],
RV #= T - P,
R2 * 200 + R1 * 100 + R50 * 50 + R20 * 20 + R10*10 #= RV,
R2 in 0..E2,
R1 in 0..E1,
R50 in 0..C50,
R20 in 0..C20,
R10 in 0..C10,
label(R).
puzzle([C,R,O,S,S] + [R,O,A,D,S] = [D,A,N,G,E,R]
) :-
C in 1..9,
R in 1..9,
D in 1..9,
O in 0..9,
S in 0..9,
A in 0..9,
N in 0..9,
E in 0..9,
G in 0..9,
all_distinct([C,R,D,O,S,A,N,E,G]),
C*10000 + R*1000 + O*100 + S*10 +S+ R*10000+ O*1000+ A*100+ D*10+ S #= D*100000+ A*10000+ N*1000+ G*100+ E*10 +R,
label([C,R,D,O,S,A,N,E,G]).