2 (:use [sicp.ch2-2 :only (enumerate-interval accumulate append flatmap)]))
4 (declare safe? empty-board adjoin-position)
6 (defn queens [board-size]
7 (let [f (fn queen-cols [k]
11 (fn [positions] (safe? k positions))
15 (adjoin-position new-row k rest-of-queens))
16 (enumerate-interval 1 board-size)))
17 (queen-cols (- k 1))))))]
22 (defn adjoin-position [row col pos]
28 (defn safe? [col positions]
29 (loop [this-row (first positions)
34 (let [new-row (first pos)]
35 (if (or (= this-row new-row)
36 (= (+ this-row offset) new-row)
37 (= (- this-row offset) new-row))
39 (recur this-row (rest pos) (inc offset)))))))