/* Problem: Write a prolog program which solves the following logic problem: Fou
ID: 3547479 • Letter: #
Question
/*
Problem:
Write a prolog program which solves the following logic problem:
Four generations of a Tennessee family have been asked to be guest panelists on a wildly-popular Idol show. From the clues below, can you work out each panelist's first name, last name, nickname and generation?
First Names - Dolly, Ellie Mae, Jed, Jethro
Last Names - Bodine, Clampett, Hatfield, McCoy
Nick Names - Clyde, Granny, Pa, Junior
1. Dolly is the youngest generation.
2. Clampett is father to Hatfield.
3. "Clyde" Jethro is Ellie Mae's grandson.
4. Granny Bodine is the oldest generation.
5. Pa is grandfather to McCoy.
*/
Explanation / Answer
//1. Dolly is the youngest generation.
clue1(Solution) :- member([Dolly, _, _, 4], Solution).
//2. Clampett is father to Hatfield.
//clue2(Solution) :- parent([_, Clampett, _, _], [_, Hatfield, _, _]).
//3. "Clyde" Jethro is Ellie Mae's grandson.
clue3(Solution) :- grandparent([Ellie Mae, _, _, _], [Jethro, _, Clyde, _]).
//4. Granny Bodine is the oldest generation.
clue4(Solution) :- member([_, Bodine, Granny, 1], Solution]).
//5. Pa is grandfather to McCoy.
clue5(Solution) :- grandparent([_, _, Pa, _], [_, McCoy, _, _]).
clue6(Solution) :- member([Jed, _, _, _], Solution).
clue7(Solution) :- member([_, _, Junior, _], Solution).
clue8(Solution) :- member([_, _, _, 2], Solution).
clue9(Solution) :- member([_, _, _, 3], Solution).
solve(Solution) :- clue1(Solution),
clue2(Solution),
clue3(Solution),
clue4(Solution),
clue5(Solution),
true.
greatgrandparent(X, Y) :- grandparent(Z, Y).
grandparent(X, Y) :- parent(Z, Y).
hope it helps
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.