Skip to content

Instantly share code, notes, and snippets.

@ndonolli
Last active May 14, 2020 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ndonolli/56cc2ad0b442a1d71f89c66788022a4f to your computer and use it in GitHub Desktop.
Save ndonolli/56cc2ad0b442a1d71f89c66788022a4f to your computer and use it in GitHub Desktop.
sudoku-validator
(defn valid-set? [s]
(= (sort s) (range 1 10)))
(defn rotate [matrix]
(apply map list matrix))
(defn rows [matrix] matrix)
(defn cols [matrix] (rotate matrix))
(defn boxes [matrix]
(->> (map (partial partition 3) matrix)
rotate flatten
(partition 9)))
(defn cell-sets [matrix]
(concat (rows matrix)
(cols matrix)
(boxes matrix)))
(defn sudoku-valid? [sudoku]
(->> (cell-sets sudoku)
(every? valid-set?)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment