# euler / clojure / 96.clj

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58``` ```; See http://projecteuler.net/index.php?section=problems&id=96 :) ; ; Answer: (refer 'clojure.set :only '(difference)) (def problem '( "003020600" "900305001" "001806400" "008102900" "700000008" "006708200" "002609500" "800203009" "005010300")) (defn char->num [c] (- (int c) (int \0))) (defstruct cell :row :col) (defn parse-row [grid row s] (loop [grid grid i 0] (if (= i (count s)) grid (let [v (char->num (nth s i))] (if (zero? v) (recur grid (inc i)) (recur (assoc grid (struct cell row i) v) (inc i))))))) (defn parse-rows [rows] (loop [grid {} row 0] (if (= row (count rows)) grid (recur (parse-row grid row (nth rows row)) (inc row))))) (defn cell-row [c] (for [col (range 9)] (struct cell (:row c) col))) (defn cell-col [c] (for [row (range 9)] (struct cell row (:col c)))) (defn box-first [n] (int (Math/floor (/ n 3)))) (defn cell-box [c] (let [row (box-first (:row c)) col (box-first (:col c))] (for [r (range 3) c (range 3)] (struct cell (+ row r) (+ col c))))) (defn cell-peers [c] (let [peers (set (concat (cell-row c) (cell-col c) (cell-box c)))] (disj peers c))) ```