Skip to content

Instantly share code, notes, and snippets.

@luxbock luxbock/sudoku.clj
Last active Aug 29, 2015

Embed
What would you like to do?
(def sudoku-board [[5 3 0 0 7 0 0 0 0]
[6 0 0 1 9 5 0 0 0]
[0 9 8 0 0 0 0 6 0]
[8 0 0 0 6 0 0 0 3]
[4 0 0 8 0 3 0 0 1]
[7 0 0 0 2 0 0 0 6]
[0 6 0 0 0 0 2 8 0]
[0 0 0 4 1 9 0 0 5]
[0 0 0 0 8 0 0 7 9]])
(defn filled?-1 [board]
(= (count (filter zero? (flatten board))) 0))
(defn filled?-2 [board]
(every? #(every? (fn [x] (> x 0)) %) board))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
sudoku> (quick-bench
(dotimes [i 10000]
(filled?-1 sudoku-board)))
WARNING: Final GC required 1.696073360113643 % of runtime
Evaluation count : 6 in 6 samples of 1 calls.
Execution time mean : 674.782332 ms
Execution time std-deviation : 60.345412 ms
Execution time lower quantile : 612.436999 ms ( 2.5%)
Execution time upper quantile : 756.834124 ms (97.5%)
Overhead used : 1.861287 ns
sudoku> (quick-bench
(dotimes [i 10000]
(filled?-2 sudoku-board)))
WARNING: Final GC required 1.5260515955602671 % of runtime
WARNING: Final GC required 13.969695599340259 % of runtime
Evaluation count : 228 in 6 samples of 38 calls.
Execution time mean : 2.653880 ms
Execution time std-deviation : 44.135387 µs
Execution time lower quantile : 2.597393 ms ( 2.5%)
Execution time upper quantile : 2.697100 ms (97.5%)
Overhead used : 1.861287 ns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.