Last active
May 24, 2016 12:52
-
-
Save zehnpaard/944a5652bede0162b903b691c57c4cb0 to your computer and use it in GitHub Desktop.
N-Queen Problem Solver in Clojure
This file contains 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
(declare valid-position?) | |
(defn n-queen [n] | |
(letfn [(f [positions i] | |
(filter valid-position? | |
(for [position positions | |
piece (map #(vector i %) (range n))] | |
(conj position piece))))] | |
(reduce f '(()) (range n)))) | |
(defn valid-position? [position] | |
(every? #(apply distinct? (map % position)) | |
[first second #(apply + %) #(apply - %)])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment