Last active
August 29, 2015 14:00
-
-
Save tungd/11372664 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns logic-puzzle.core | |
(:refer-clojure :exclude [==]) | |
(:require [clojure.core.logic :refer :all])) | |
(defn squaro [q] | |
(let [colors [:red :green :blue :yellow]] | |
(fresh [a1 a2 a3 a4 | |
b1 b2 b3 b4] | |
(all | |
(permuteo colors [a1 a2 a3 a4]) | |
(permuteo colors [b1 b2 b3 b4]) | |
(!= a1 b1) | |
(!= a2 b2) | |
(!= a3 b3) | |
(!= a4 b4) | |
(== q [a1 a2 a3 a4 b1 b2 b3 b4]))))) | |
(run 1 [q] | |
(squaro q)) | |
;; => ([:red :green :blue :yellow :green :blue :yellow :red]) | |
(count (run* [q] (squaro q))) | |
;; => 216 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Each of the squares of two rows of squares (2x4) is coloured in one of 4 di�erent colours red, yellow, green and blue. Find the number of ways of colouring the two rows so that each row has 4 di�erent colours and no two adjacent squares are of the same colour. (Two squares are adjacent if they share a common side.)