tile([brown,gray,yellow,blue,green,red]).
tile([brown,green,red,blue,yellow,gray]).
tile([brown,green,gray,yellow,blue,red]).
tile([brown,gray,red,yellow,green,blue]).
tile([brown,red,blue,yellow,green,gray]).
tile([brown,yellow,green,blue,red,gray]).
tile([brown,green,red,gray,yellow,blue]).
color(rot(T,R),N,C) :- between(0,5,R), N0 is (N + R) mod 6, nth0(N0,T,C).
connected(T1,N,T2) :- color(T1,N,C), N1 is (N + 3) mod 6, color(T2,N1,C).
solution(X) :- findall(rot(T,_),tile(T),Ts), permutation(Ts,X),
X = [T0,T1,T2,T3,T4,T5,T6],
connected(T0,2,T1), connected(T0,3,T6),
connected(T1,3,T2), connected(T1,4,T6),
connected(T2,4,T3), connected(T2,5,T6),
connected(T3,5,T4), connected(T3,0,T6),
connected(T4,0,T5), connected(T4,1,T6),
connected(T5,1,T0), connected(T5,2,T6).