Do you think this toothbrush riddle can be expressed in Prolog?

Hi there,
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.

    1. The child with the yellow toothbrush uses toothpaste Ideal Med 3.
    1. It‘s not the 10 year old that uses toothpaste Dentix
    1. Fabienne stays between the 11 year old and Julia
    1. Florian uses toothpaste Dental
    1. Severin uses the blue toothbrush
    1. The 12.5 year old uses toothpaste Dent O Med.
    1. Severin is 12 years old
    1. Florian uses the green toothbrush
    1. The second child is 11 years old
    1. 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?

Thank you,
Markus

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.

If you search for [who owns the zebra], you’ll find many variations of this puzzle. If you search for [who owns the zebra prolog], you’ll find some ways of solving it, including https://swish.swi-prolog.org/example/houses_puzzle.pl

2 Likes

Peter, thank you a lot!
SWISH is very pleasant surprise, too.

I am going to study houses:puzzle.pl