 (defn valid-board? [board]
   (and
     (every? (partial get-in board) all-cells)
-    (empty? (bad-cells board))))+    (empty? (bad-cells board))))

(ns clojure-club.sudoku.mbastian)

;Copied from https://github.com/markbastian/sudoku/blob/master/src/cljc/sudoku/rules.cljc
(def valid-values (apply hash-set (range 1 10)))

(defonce all-cells (for [i (range 9) j (range 9)] [i j]))

                          [a b])))]
           (zipmap all-cells (map #(disj (reduce into #{} (cells %)) %) all-cells))))

(defn set-cell [board cell value]
  (letfn [(safe-set [b c] (cond-> b (set? (get-in b c)) (update-in c disj value)))]
    (-> (reduce safe-set board (neighbors cell)) (assoc-in cell value))))

(defn most-constrained [board]
  (->> all-cells
       (filter #(set? (get-in board %)))
       (apply min-key #(count (get-in board %)))))

(defn initialize [problem]
  (reduce
    (fn [board cell]
      (if-let [v (valid-values (get-in problem cell))]
        (set-cell board cell v)
        board))
    (vec (repeat 9 (vec (repeat 9 valid-values))))
    all-cells))

(defn solve-step [board]
  (let [best-cell (most-constrained board)]
    (for [v (get-in board best-cell)] (set-cell board best-cell v))))

(def hard
  '[[_ _ _ _ _ _ _ 1 2]
