Title: Minor Confusion
Solved by: Doug Edmunds
Publication: Dell Logic Puzzles
Issue: April, 1998
Page: 36
Stars: 4

Clues

/*
Dell Logic Puzzles 4/98 Edition p36 Minor Confusion (4 star)
updated solution 20 Mar 2001

by adding the 'alldifferent' lines
(which appear between Units and Constraints)
the solution time went from 12+ seconds on PII-350
to <.5 seconds.

ID, Son Nickname Position City Team)
unit(1, aaron, string, pitch, nport, navigat),
unit(2, dave, tiny, tbase, pensa, pumas),
unit(3, gary, dizzy, short, martins, greensox),
unit(4, jon, lefty, fbase, baton, catfish),
unit(5, ray, bigfoot, rfield, trenton, eels),
unit(6, stan, choo, cfield, fortw, tornados)]
*/

:- use_module(library(fd)).
:- writeln("type: start(Units)").

start(Units) :-

Units =
[
unit(1,aaron,_,_,_,_),
unit(2,dave ,_,_,_,_),
unit(3,gary ,_,_,_,_),
unit(4,jon ,_,_,_,_),
unit(5,ray ,_,_,_,_),
unit(6,stan ,_,_,_,_)

],

[ A , D, G, J, R, S,
BI, CH, DI, LE, ST, TI,
CF, FB, PI, RF, SS, TB,
BA, FO, MA, NO, PE, TR,
CA, EE, GR, NA, PU, TO
] ::[1..6],

alldifferent([A,D,G,J,R,S]),
alldifferent([BI,CH,DI,LE,ST,TI]),
alldifferent([CF,FB,PI,RF,SS,TB]),
alldifferent([BA,FO,MA,NO,PE,TR]),
alldifferent([CA,EE,GR,NA,PU,TO]),

Constraints =
[
unit(A,aaron,_,_,_,_),
unit(D,dave ,_,_,_,_),
unit(G,gary ,_,_,_,_),
unit(J,jon ,_,_,_,_),
unit(R,ray ,_,_,_,_),
unit(S,stan ,_,_,_,_),

unit(BI,_,bigfoot,_,_,_),
unit(CH,_,choo ,_,_,_),
unit(DI,_,dizzy ,_,_,_),
unit(LE,_,lefty ,_,_,_),
unit(ST,_,string ,_,_,_),
unit(TI,_,tiny ,_,_,_),

unit(CF,_,_,cfield,_,_),
unit(FB,_,_,fbase ,_,_),
unit(PI,_,_,pitch ,_,_),
unit(RF,_,_,rfield,_,_),
unit(SS,_,_,short ,_,_),
unit(TB,_,_,tbase ,_,_),

unit(BA,_,_,_,baton ,_),
unit(FO,_,_,_,fortw ,_),
unit(MA,_,_,_,martins,_),
unit(NO,_,_,_,nport ,_),
unit(PE,_,_,_,pensa ,_),
unit(TR,_,_,_,trenton,_),

unit(CA,_,_,_,_,catfish ),
unit(EE,_,_,_,_,eels ),
unit(GR,_,_,_,_,greensox),
unit(NA,_,_,_,_,navigat ),
unit(PU,_,_,_,_,pumas ),
unit(TO,_,_,_,_,tornados)
] ,

%clue 1
some_order(ST,FO,TO,NA),
one_of_2_is(ST,FO,A),

%clue 2
D ##FB,
one_of_2_is(D,FB,CA),
BA #=CA,

%clue 3
alldifferent([J,TI,EE,MA]),

%clue 4
alldifferent([LE,TO,NO]),
one_of_3_is(LE,TO,NO,CF),

%clue 5
BI #=TR,

%clue 6
SS ## D,
SS ## R,
SS ## EE,
SS ## PU,

%clue 7
one_of_2_is(A,J,PI),

%clue 8
D ##RF,

%clue 9
DI #=GR,
GR ## NO,

%clue 10
PU ## NO,
one_of_2_is(PU,NO,TI),

%clue 11
R ## PE,

%clue 12
S #= CH,

psubset(Constraints, Units),
(foreach(Unit,Units) do writeln(Unit)).


psubset([],_).
psubset([H|T],List) :-
member(H,List),
psubset(T,List).


some_order(ST,FO,TO,NA):- ST #=TO, FO #=NA.
some_order(ST,FO,TO,NA):- ST #=NA, FO #=TO.


one_of_2_is(DA,FB,CA):-DA #=CA; FB #=CA.

one_of_3_is(LE,_TO,_NO,CF):- LE #=CF.
one_of_3_is(_LE,TO,_NO,CF):- TO #=CF.
one_of_3_is(_LE,_TO,NO,CF):- NO #=CF.


% © Copyright Doug Edmunds 2001