% © Copyright Doug Edmunds 2000
/*
Dell Logic Puzzles 4/98 Edition p12
Title: Pro and Con (2 star)
Solved 14 Nov 1999
takes considerably longer than most
to produce a solution
motions: 1 2 3 4 5
names: a b c d e
votes: yes or no on each
correct solution
each sequence:
voter(Vote1, Vote2, Vote3, Vote4, Vote5): 1 is yes, 0 is no
a(1, 1, 1, 1, 0)
b(1, 0, 1, 1, 0)
c(1, 0, 1, 0, 0)
d(1, 1, 0, 0, 0)
e(1, 1, 1, 0, 0)
*/
:- use_module(library(fd)).
:- writeln("type: start(Units)").
start(Units) :-
Units =
[
vote(akerman,m1,_),
vote(akerman,m2,_),
vote(akerman,m3,_),
vote(akerman,m4,_),
vote(akerman,m5,_),
vote(baird ,m1,_),
vote(baird ,m2,_),
vote(baird ,m3,_),
vote(baird ,m4,_),
vote(baird ,m5,_),
vote(chatham,m1,_),
vote(chatham,m2,_),
vote(chatham,m3,_),
vote(chatham,m4,_),
vote(chatham,m5,_),
vote(duval ,m1,_),
vote(duval ,m2,_),
vote(duval ,m3,_),
vote(duval ,m4,_),
vote(duval ,m5,_),
vote(etting ,m1,_),
vote(etting ,m2,_),
vote(etting ,m3,_),
vote(etting ,m4,_),
vote(etting ,m5,_)
],
[A1,A2,A3,A4,A5,B1,B2,B3,B4,B5,C1,C2,C3,C4,C5,
D1,D2,D3,D4,D5,E1,E2,E3,E4,E5] ::0..1,
Constraints =
[
vote(akerman,m1,A1),
vote(akerman,m2,A2),
vote(akerman,m3,A3),
vote(akerman,m4,A4),
vote(akerman,m4,1), %clue 6
vote(akerman,m5,A5),
vote(baird ,m1,B1),
vote(baird ,m2,B2),
vote(baird ,m3,B3),
vote(baird ,m4,B4),
vote(baird ,m4,1), % clue 6
vote(baird ,m5,B5),
vote(chatham,m1,C1),
vote(chatham,m2,C2),
vote(chatham,m3,C3),
vote(chatham,m4,C4),
vote(chatham,m5,C5),
vote(duval ,m1,D1),
vote(duval ,m2,D2),
vote(duval ,m3,D3),
vote(duval ,m4,D4),
vote(duval ,m5,D5),
vote(etting ,m1,E1),
vote(etting ,m2,E2),
vote(etting ,m3,E3),
vote(etting ,m4,E4),
vote(etting ,m5,E5)
],
AllVars = [A1,A2,A3,A4,A5,B1,B2,B3,B4,B5,C1,C2,C3,C4,C5,
D1,D2,D3,D4,D5,E1,E2,E3,E4,E5],
%Clue 8
M3 #= M4 * 2,
%Clue 7
M1 #= M2 + 2,
[M1,M2,M3,M4,M5] ::0..5,
M1 #= A1 + B1 + C1+ D1+ E1,
M2 #= A2 + B2 + C2+ D2+ E2,
M3 #= A3 + B3 + C3+ D3+ E3,
M4 #= A4 + B4 + C4+ D4+ E4,
M5 #= A5 + B5 + C5+ D5+ E5,
% clue 2
%calc outside program Y+N =25, Y +3 = N, 14,11
M1 + M2 +M3 + M4 + M5 #= 14,
labeling(AllVars),
%Clue 1
alldifferent([M1,M2,M3,M4,M5]),
%Clue 2 calculate and solve
%it can't figure this out! 14 - 11
%[Yesvotes,Novotes]::[0..25],
%Novotes #= Vesvotes - 3,
%Yesvotes + Novotes #= 25,
%writeln (Yesvotes),
% --
%works if only 1 variable
%[Yesvotes]::[0..25],
%Yesvotes + Yesvotes + 3 #= 25,
%M1 + M2 +M3 + M4 + M5 #= Yesvotes,
%clue 3 instantiate first,
% no two same voting pattern
AL = A1*10000 + A2*1000 + A3*100 +A4*10 + A5,
BL = B1*10000 + B2*1000 + B3*100 +B4*10 + B5,
CL = C1*10000 + C2*1000 + C3*100 +C4*10 + C5,
DL = D1*10000 + D2*1000 + D3*100 +D4*10 + D5,
EL = E1*10000 + E2*1000 + E3*100 +E4*10 + E5,
Allseq = [AL,BL,CL,DL,EL],
alldifferent(Allseq),
Aseq = a(A1, A2, A3,A4, A5),
Bseq = b(B1, B2, B3,B4, B5),
Cseq = c(C1, C2, C3,C4, C5),
Dseq = d(D1, D2, D3,D4, D5),
Eseq = e(E1, E2, E3,E4, E5),
%clue 5
% C vote does not have 2 consec y votes
not2cons(Cseq[1], Cseq[2]),
not2cons(Cseq[2], Cseq[3]),
not2cons(Cseq[3], Cseq[4]),
not2cons(Cseq[4], Cseq[5]),
%clue 4 -
disagreed_more(Bseq,Dseq),
psubset(Constraints, Units),
writeln(Aseq),
writeln(Bseq),
writeln(Cseq),
writeln(Dseq),
writeln(Eseq).
psubset([],_).
psubset([H|T],List) :-
member(H,List),
psubset(T,List).
not2cons(D1, D2):-
(#=(D1,1,1),#=(D2,1,1)) -> fail; true.
disagreed_more(B,D) :-
#=(B[1],D[1],Bool1),
#=(B[2],D[2],Bool2),
#=(B[3],D[3],Bool3),
#=(B[4],D[4],Bool4),
#=(B[5],D[5],Bool5),
BoolTotal #= Bool1 + Bool2 + Bool3 + Bool4 + Bool5,
(BoolTotal #>= 3) -> fail; true.