% MIT License % Copyright (C) 2025 Shintaro Mukai. % https://mukai.systems/articles/m8m4aqtkt8n3etkp2hocqp4tpdmhhl64/ % Zebra puzzle solver. next_month(july, august). next_month(august, september). next_month(september, october). solve1(A) :- [[A11, A12, A13], [A21, A22, A23], [A31, A32, A33]] = A, [A11, A21, A31] = [aida, iida, ueda], permutation([crane, helmet, flower], [A12, A22, A32]), permutation([red, blue, green], [A13, A23, A33]), member([aida, flower, _], A), member([_, crane, green], A), member([iida, _, blue], A). solve2(A) :- [[A11, A12, A13], [A21, A22, A23], [A31, A32, A33], [A41, A42, A43]] = A, [A11, A21, A31, A41] = [july, august, september, october], permutation([portrait, scenery, animal, fruit], [A12, A22, A32, A42]), permutation([colored_pencils, crayons, oil_paint, watercolors], [A13, A23, A33, A43]), member([july, portrait, _], A), member([M_colored_pencils, scenery, colored_pencils], A), M_colored_pencils \= october, member([M_crayons, _, crayons], A), member(M_crayons, [july, august]), member([M_oil_paint, W_oil_paint, oil_paint], A), M_oil_paint \= august, W_oil_paint \= animal, member([M_watercolors, _, watercolors], A), next_month(M_watercolors, M_oil_paint).