Permalink
Browse files

exploding code lein midje didn't appear to pick up until restart

  • Loading branch information...
IanEsling committed Jun 6, 2012
1 parent b352ba7 commit 1eee587d12977eff6688ea3ae240a8de48ea096f
View
@@ -8,7 +8,7 @@
(conj newboardseq (into {} (for [x (f-x-range) y (f-y-range)]
(assoc regions-board [x y] (get board [x y])))))))
-(defn- create-cell-numbers
+(defn create-cell-numbers
[x]
(if (re-matches (re-pattern "[1-9]") (str x))
(hash-set x)
@@ -8,13 +8,6 @@
[board]
(reduce #(+ %1 (count %2)) 0 (numbers-of-unsolved-cells board)))
-(defn- solver-function
- [solver-f get-units-f]
- (fn [board-map]
- (if-let [solved (:solved board-map)]
- board-map
- (solve-units solver-f get-units-f (:board board-map)))))
-
(defn solve-units
[unit-solver-f get-units-f board]
(loop [units (get-units-f board)
@@ -29,6 +22,13 @@
(recur (next units) (conj newboard unit) true))
(assoc {:solved solved} :board newboard))))
+(defn- solver-function
+ [solver-f get-units-f]
+ (fn [board-map]
+ (if-let [solved (:solved board-map)]
+ board-map
+ (solve-units solver-f get-units-f (:board board-map)))))
+
(defn run-solvers
[board & unit-solver-fs]
(loop [fs unit-solver-fs
@@ -53,7 +53,7 @@ cell must be that number"
9 8 0 6 5 4 3 0 0
]) partially-solved))
- (def board-after-solving (into {} (:board ((partial solve-unit only-possible-number-in-unit) get-rows board))))
+ (def board-after-solving (into {} (:board ((partial solve-units only-possible-number-in-unit) get-rows board))))
(count board-after-solving) => 81
(count (get-row-number 1 board-after-solving)) => 9
(count (get-row-number 2 board-after-solving)) => 9
@@ -87,7 +87,7 @@ cell must be that number"
0 9 1 0 5 4 3 0 0
]) partially-solved))
- (def board-after-solving (into {} (:board ((partial solve-unit only-possible-number-in-unit) get-columns board))))
+ (def board-after-solving (into {} (:board ((partial solve-units only-possible-number-in-unit) get-columns board))))
(count board-after-solving) => 81
(count (get-column-number 1 board-after-solving)) => 9
(count (get-column-number 2 board-after-solving)) => 9
@@ -121,7 +121,7 @@ cell must be that number"
0 9 1 0 5 4 3 0 0
]) partially-solved))
- (def board-after-solving (into {} (:board ((partial solve-unit only-possible-number-in-unit) get-regions board))))
+ (def board-after-solving (into {} (:board ((partial solve-units only-possible-number-in-unit) get-regions board))))
(count board-after-solving) => 81
(count (get-region-number 2 board-after-solving)) => 9
(count (get-region-number 4 board-after-solving)) => 9
@@ -11,19 +11,19 @@
(fact "cell numbers are always sets after solving"
;check all numbers are still in sets
- (for [cell (filter #(= 1 (first (key %))) (into {} (:board (solve-unit remove-solved-numbers-from-unit get-rows (create-board [1 2 3 4 5 6 7 8 0])))))]
+ (for [cell (filter #(= 1 (first (key %))) (into {} (:board (solve-units remove-solved-numbers-from-unit get-rows (create-board [1 2 3 4 5 6 7 8 0])))))]
(set? (second cell))
) => (repeat 9 true)
)
(fact "a solved board is not equal to the original board"
(def board (create-board [1 2 3 4 5 6 7 8 0]))
- (into {} (:board (solve-unit remove-solved-numbers-from-unit get-rows board))) =not=> (just board :in-any-order )
+ (into {} (:board (solve-units remove-solved-numbers-from-unit get-rows board))) =not=> (just board :in-any-order )
)
(fact "if the solver makes no changes the new board is equal to the original board"
(def board (create-board [1 2 3 4 5 6 7 8 9]))
- (into {} (:board (solve-unit remove-solved-numbers-from-unit get-rows board))) => (just board :in-any-order )
+ (into {} (:board (solve-units remove-solved-numbers-from-unit get-rows board))) => (just board :in-any-order )
)
(fact "the solvers should keep on running until they can't remove any more possible numbers from the unsolved cells"

0 comments on commit 1eee587

Please sign in to comment.