Hello marvelous Prolog community,
I watched Vsauces’ recent Future of Reasoning video on YouTube (https://youtu.be/_ArVh3Cj9rw?t=590) where he presented his audience with a simple logical puzzle:
Paul is looking at Mary.
Mary is looking at Peter.
Paul is married.
Peter is unmarried.
Is a married person looking at an unmarried person?
I wanted to specify this puzzle in Prolog, naturally I turned to clp libraries for this. I ended up using the following formulation:
:- use_module(library(clpfd)).
?- [Paul, Peter, Mary] ins 0..1,
LookingAts = [Paul-Mary, Mary-Peter],
Paul #= 1, Peter #= 0,
member(1-0, LookingAts).
Paul = 1,
Peter = Mary, Mary = 0,
LookingAts = [1-0, 0-0] ;
Paul = Mary, Mary = 1,
Peter = 0,
LookingAts = [1-1, 1-0].
I encoded married as 1 and unmarried as 0, and placed looking at facts in a list which I eventually query to find solutions for a married person looking at an unmarried person
with member(1-0, LookingAts)
I’m fairly inexperienced in clp and Prolog generally, but still I don’t find this solution overly satisfactory. Is there perhaps a more elegant, perhaps more readable or idiomatic way of expressing this puzzle?
Regards,
Drazen