Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Solving a riddle

Status
Not open for further replies.

infomation07

Programmer
Mar 24, 2007
1
DE
Hello Community!
I am working on solving a riddle right now. I have defined the below clues but, it is not working. I think the ones where I use members is wrong. I am pretty new, so maybe the is also a typo? Can anyone help me, please? I need that until sunday evening.

driver(afra).
driver(gerda).
driver(hassan).
driver(tim).

allChildren([]).
allChildren([F|R]) :- driver(F), allChildren(R).

allDifferent([]).
allDifferent([F|R]) :- not(member(F,R)), allDifferent(R).

gasList(L) :- length(L, 4), allChildren(L), allDifferent(L).

% Structure of Location:
% [carWash, gasPump1, gasPump2, airPump]
% Structure of Brand:
% [bmw, jaguar, renault, toyota]
% Structure of Color:
% [darkBlue, grey, green, lightBlue]

clue1([_,_,_,X], [_,X,_,_], [_,X,_,_]) :- driver(X), not(X = hassan). % The grey jaguar is more to the right than car of hassan
clue2([_,_,_,_], [_,_,_,_], [X,_,_,X]) :- driver(X), not(X=tim). % Tim has no blue car
clue3([_,X,X,_], [X,_,_,_], [_,_,_,_]) :- driver(X), not(X=afra). % The car of afra, is not the bmw and does not pump gas.
%clue4([_,X,X,_], [_,_,_,X], [_,_,X,_]) :- member(X). % The toyota is green and pumps gas.
%clue5([_,_,_,_], [_,_,X,_], [X,_,_,_]) :- member(X), not(X= renault). % The Renault is not darkBlue
%clue6([_,_,_,X], [_,_,_,_], [X,_,_,_]) :- member(X). % The Car at the airPump is darkBlue
clue7([_,_,_,_], [_,_,_,_], [_,_,_,X]) :- driver(X), not(X = gerda). % Gerdas Car is not lightBlue

solvePuzzle(Location, Brand, Color) :-
gasList(Location),
gasList(Brand),
gasList(Color),
clue1(Location, Brand, Color),
clue2(Location, Brand, Color),
clue3(Location, Brand, Color),
clue4(Location, Brand, Color),
clue5(Location, Brand, Color),
clue6(Location, Brand, Color),
clue7(Location, Brand, Color).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top