I am trying to solve a puzzle in prolog and i made only a part of it, i can't figure out how to finish it. This is the problem:
Consider four men with last names of Baker, Carpenter, Miller, and Farmer. Assume that the four professions represented by this group include a baker, a carpenter, a miller, and a farmer. Assume further that each person has a profession that does not correspond to their last name.
Each of these four men has a son. The four sons have professions of baker, carpenter, miller, and farmer. Assume again that each person has a profession that does not correspond to their last name.
Assume that we also know the following facts: No son has the same profession as his father. Baker has the same profession as the carpenter's son. The farmer's son is a baker.
The part I cannot figure out how to implement is:
Baker has the same profession as the carpenter's son.
The farmer's son is a baker.
This is my code for the part of the problem that i made so far:
DOMAINS
father = father(lastname,profession)
son = son(lastname2,profession2)
list2 = son*
list = father*
lastname = string
profession = string
lastname2 = string
profession2 = string
PREDICATES
nondeterm member(father, list)
nondeterm member(son,list2)
solution
CLAUSES
member(Item, [Item|_]).
member(Item,[_|Tail]) :- member(Item,Tail).
solution:-
List = [father("Baker" , BakerFatherJob),
father("Carpenter" , CarpenterFatherJob),
father("Miller" , MillerFatherJob),
father("Farmer",FarmerFatherJob)],
List2 = [son("Baker" , BakerSonJob),
son("Carpenter" , CarpenterSonJob),
son("Miller" , MillerSonJob),
son("Farmer",FarmerSonJob)],
member(father(_, "Baker"), List),
member(father(_, "Carpenter"), List),
member(father(_, "Miller"), List),
member(father(_, "Farmer"), List),
member(son(_, "Baker"), List2),
member(son(_, "Carpenter"), List2),
member(son(_, "Miller"), List2),
member(son(_, "Farmer"), List2),
BakerFatherJob<>BakerSonJob,
CarpenterFatherJob<>CarpenterSonJob,
MillerFatherJob<>MillerSonJob,
FarmerFatherJob<>FarmerSonJob,
BakerFatherJob <> "Baker",
CarpenterFatherJob <> "Carpenter",
MillerFatherJob <> "Miller",
FarmerFatherJob <> "Farmer",
BakerSonJob <> "Baker",
CarpenterSonJob <> "Carpenter",
MillerSonJob <> "Miller",
FarmerSonJob <> "Farmer",
write("Father Baker has job ", BakerFatherJob),nl,
write("Father Carpenter has job ", CarpenterFatherJob), nl,
write("Father Miller has job ", MillerFatherJob),nl,
write("Father Farmer has job ", FarmerFatherJob),nl,
write(" "), nl,
write("Son Baker has job ", BakerSonJob),nl,
write("Son Carpenter has job ", CarpenterSonJob), nl,
write("Son Miller has job ", MillerSonJob),nl,
write("Son Farmer has job ", FarmerSonJob),nl,
write(" "), nl,
fail.
solution:-
write(" ALL SOLUTIONS HAVE BEEN FOUND")