I have source code can someone help me fix it? i have never used prolog before,
ID: 3776824 • Letter: I
Question
I have source code can someone help me fix it? i have never used prolog before, and i cant find whats wrong with my code?
price(107).
price(111).
price(115).
price(119).
price(123).
town(irvine).
town(lewis).
town(santa_rosa).
town(tecopa).
town(zamora).
solve :-
price(BallantinesPrice), price(EnergoPrice), price(GngPrice), price(FsPrice),
price(VexonPrice),
all_different([BallantinesPrice, EnergoPrice, GngPrice, FsPrice, VexonPrice]),
town(BallantinesTown), town(EnergoTown),
town(GngTown), town(FsTown), town(VexonTown),
all_different([BallantinesTown, EnergoTown, GngTown,
FsTown, VexonTown]),
Group = [ [ballantines, BallantinesPrice, BallantinesTown],
[energo, EnergoPrice, EnergoTown],
[gng, GngPrice, GngTown],
[fs, FsPrice, FsTown],
[vexon, VexonPrice, VexonTown]],
%1 Fuel Stop charges somewhat less per gallon than Vexon.
member([fs,X,_],Group, member([vexon,Y,_],Group), X < Y,
%2 The business in Irvine charges somewhat more per gallon than the business in Santa Rosa.
%3 Gas-N-Go doesn't charge $1.23 per gallon.
not(member([gng,123,_],Group),
%4 The gas station in Lewis charges 8 cents less per gallon than the store in Zamora.
%5 Fuel Stop charges 8 cents less per gallon than the store in Santa Rosa.
%6 The business in Lewis is either Vexon or Energo.
member([[vexon|energo], _, lewis], Group),
%7 Fuel Stop charges 4 cents less per gallon than Ballantines.
tell(ballantines, BallantinesPrice, BallantinesTown),
tell(energo, EnergoPrice, EnergoTown),
tell(gng, GngPrice, GngTown),
tell(fs, FsPrice, FsTown),
tell(vexon, VexonPrice, VexonTown).
% Succeeds if all elements of the argument list are bound and different.
% Fails if any elements are unbound or equal to some other element.
all_different([H | T]) :- member(H, T), !, fail.
all_different([_ | T]) :- all_different(T).
all_different([_]).
tell(X, Y, Z) :-
write(X), write(' costs '), write(Y),
write(' and is located in '), write(Z), write('.'), nl.
Explanation / Answer
everything is fine in your code but you have missed two closing parenthesis
here the first call to member/2 just below %1 and other call to member under %3
edited code
price(107).
price(111).
price(115).
price(119).
price(123).
town(irvine).
town(lewis).
town(santa_rosa).
town(tecopa).
town(zamora).
solve :-
price(BallantinesPrice), price(EnergoPrice), price(GngPrice), price(FsPrice),
price(VexonPrice),
all_different([BallantinesPrice, EnergoPrice, GngPrice, FsPrice, VexonPrice]),
town(BallantinesTown), town(EnergoTown),
town(GngTown), town(FsTown), town(VexonTown),
all_different([BallantinesTown, EnergoTown, GngTown,
FsTown, VexonTown]),
Group = [ [ballantines, BallantinesPrice, BallantinesTown],
[energo, EnergoPrice, EnergoTown],
[gng, GngPrice, GngTown],
[fs, FsPrice, FsTown],
[vexon, VexonPrice, VexonTown]],
%1 Fuel Stop charges somewhat less per gallon than Vexon.
member([fs,X,_],Group), member([vexon,Y,_],Group), X < Y,
%2 The business in Irvine charges somewhat more per gallon than the business in Santa Rosa.
%3 Gas-N-Go doesn't charge $1.23 per gallon.
not(member([gng,123,_],Group)),
%4 The gas station in Lewis charges 8 cents less per gallon than the store in Zamora.
%5 Fuel Stop charges 8 cents less per gallon than the store in Santa Rosa.
%6 The business in Lewis is either Vexon or Energo.
member([[vexon|energo], _, lewis], Group),
%7 Fuel Stop charges 4 cents less per gallon than Ballantines.
tell(ballantines, BallantinesPrice, BallantinesTown),
tell(energo, EnergoPrice, EnergoTown),
tell(gng, GngPrice, GngTown),
tell(fs, FsPrice, FsTown),
tell(vexon, VexonPrice, VexonTown).
% Succeeds if all elements of the argument list are bound and different.
% Fails if any elements are unbound or equal to some other element.
all_different([H | T]) :- member(H, T), !, fail.
all_different([_ | T]) :- all_different(T).
all_different([_]).
tell(X, Y, Z) :-
write(X), write(' costs '), write(Y),
write(' and is located in '), write(Z), write('.'), nl.