简体   繁体   中英

How to solve this logic puzzle in prolog?

  1. A,B,C,D,E,F is one list.
  2. C is before E
  3. A is after F
  4. E is not in fifth
  5. There are two between E and A
  6. After B is E, B is adjacent to E

Which one is the fourth ?

Finally I solved the problem by myself

before(A,B) :- A<B.
after(A,B) :- A>B.
notInFifth(A) :- A \= 5.
adjacent(A,B) :- abs(A - B) =:= 1.
separatedByTwo(A,B) :- abs(A - B) =:= 2.


solution(A,B,C,D,E,F) :-
    permutation([1,2,3,4,5,6], [A,B,C,D,E,F]),
    notInFifth(E),
    separatedByTwo(D,A),
    adjacent(B,E),
    before(C,E),
    before(F,A),
    before(E,B).

list is : cebdfa

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM