Last active
May 14, 2020 21:51
-
-
Save ndonolli/56cc2ad0b442a1d71f89c66788022a4f to your computer and use it in GitHub Desktop.
sudoku-validator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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