my only contact with Prolog is 30 years ago, in a course in university.
A friend of work asked me for help on homework of his children.
The homework is to solve this riddle:
4 children of fifth grade (around 10-11 years) want to brush their teeth.
- The child with the yellow toothbrush uses toothpaste Ideal Med 3.
- It‘s not the 10 year old that uses toothpaste Dentix
- Fabienne stays between the 11 year old and Julia
- Florian uses toothpaste Dental
- Severin uses the blue toothbrush
- The 12.5 year old uses toothpaste Dent O Med.
- Severin is 12 years old
- Florian uses the green toothbrush
- The second child is 11 years old
- No children directly beside Florian use the red toothbrush
I cannot find a solution.
The below attempt only tells me that Severin is either 12 or 10.
My idea was that this homework could be an interesting starting point for learning Prolog, but I fail to express the riddle in Prolog
Do you think this riddle can be expressed in Prolog?
age(severin, 12). %% 7 age(Child, 10) :- toothpaste(Child, dental); toothpaste(Child, idealmed3); toothpaste(Child, dentomed). %% 2 age(Child, 12.5) :- toothpaste(Child, dentomed). %% 6 child(fabienne). child(florian). child(julia). child(severin). toothbrush(blue). toothbrush(green). toothbrush(red). toothbrush(severin, blue). %% 5 toothbrush(florian, green). %% 8 toothpaste(dental). toothpaste(dentix). toothpaste(idealmed3). toothpaste(dentomed). toothpaste(florian, dental). %% 4 toothpaste(Child, idealmed3) :- toothbrush(Child, yellow). %% 1 order(Child1, Child2) :- child(Child1), child(Child2), %% age(Child2, 11), %% 9 Child1 \= Child2.