10 lines
461 B
Clojure
10 lines
461 B
Clojure
(defn n-queens [n]
|
|
(let[children #(map (partial conj %) (range n))
|
|
no-conflict? (fn [x] (or (empty? x)
|
|
(every? #(apply distinct? (map-indexed % x))
|
|
[+ - (fn[_ v] v)])))]
|
|
(filter (every-pred no-conflict? #(= n (count %)))
|
|
(tree-seq (every-pred #(> n (count %))
|
|
no-conflict?)
|
|
children []))))
|