write a prolog program which solves the following logic problem: Four married ge
ID: 3602227 • Letter: W
Question
write a prolog program which solves the following logic problem: Four married generations of a German family have been asked to be guest panelists. From the clues below, can you work out each panelist couple's first names, nicknames, hair colors and generations? First Names - alex, doty, gerhardt, jil, maria, pietra, sophie, viktor Nick Names - bieraffe, eis, hund, kraftwerk, nachtforster, qualitat, teufelhund, xerxes Hair Color - cyan, fuchsiefarbe, indigo, lila, orange, rot, umbrabraun, zeitblond 1. alex, gerhardt, pietra, and viktor are men. 2. cyan alex and fuchsiefarbe eis are the youngest generation. 3. gerhardt is doty's parent. 4. indigo hund is teufelhund sophie's grandchild. 5. zeitblond viktor is the oldest generation. 6. zeitblond xerxes is grandparent to jil kraftwerk. 7. orange nachtforster and qualitat rot is grandparent to alex and eis. 8. bieraffe is a grandchild of pietra. 9. lila is married to gerhardt. 10. sophie umbrabraun. 11. maria nachtforster.
Explanation / Answer
- show quoted text -
Here's a start:
You need to search the space of possible person(Name, Sex, Nick, Hair, ParentName) terms for a set that covers all the names and is consistent with all the given rules. Once you have that you can calculate the generation for each by counting the chain of parents above it. Once you have the generations you know the couples.
In Prolog usually the simplest way to do a search is to let the automagic backtracking run through the possibilities, which unbinds and then rebinds variables.
So, you can start with the following:
People = [ person(alex, m, _, _, _),
person(doty, f, _, _, _),
person(gerhardt, m, _, _, _),
person(oil, f, _, _, _),
person(maria, f, _, _, _),
person(pietra, m, _, _, _),
person(sophie, f, _, _, _),
person(viktor, m, _, _, _) ],
This includes the information from rule 1.
Then code each of rules 2 - 11. For example, here is rule 4 "indigo hund is teufelhund sophie's grandchild":
member(People, person(_, _, hund, indigo, R4Parent)),
member(People, person(R4Parent, _, _, _, R4GrandParent)),
member(People, person(sophie, _, teufelhund, _, R4GrandParent)),
(The R4 prefix prevents clashes with similar intermediate variables in other rule numbers.)
After (hopefully!) succeeding on all the rules, People will have all the known info bound.
Have fun.
--
---------------------------
| BBB b Barbara at LivingHistory stop co stop uk
| B B aa rrr b |
| BBB a a r bbb | ,008015L080180,022036,029037
| B B a a r b b | ,047045,L014114L4.
| BBB aa a r bbb |
-----------------------------
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.