The criminal is one of A, B, C and D.
A says: "It's not me"
B says: "It's D"
C says: "It's B"
D says: "It's not me"
And we know that only one of them tells the truth.
Who is the one? I want to solve it by using Prolog.
It's an interview question.
One-liner solution
?- member(K,[a,b,c,d]),(K\=a->A=1;A=0),(K=d->B=1;B=0),(K=b->C=1;C=0),(K\=d->D=1;D=0),A+B+C+D=:=1.
K = a,
A = 0,
B = 0,
C = 0,
D = 1 ;
false.
A similar problem and corresponding solution can also be found here:
https://github.com/LogtalkDotOrg/logtalk3/blob/master/examples/puzzles/jam_thief.lgt
Like the solution posted by Kaarel, is possible to request a justification/explanation for the solution found.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With