Solving a logic puzzle using Prolog

前端 未结 5 537
鱼传尺愫
鱼传尺愫 2020-12-13 16:27

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\"

5条回答
  •  有刺的猬
    2020-12-13 17:01

    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.
    

提交回复
热议问题