Last active
August 29, 2015 14:20
-
-
Save kidpollo/61f4d57543ce8619901a to your computer and use it in GitHub Desktop.
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
(ns sudoku-validator.core) | |
(defn is-valid-solution [grid] | |
(let [rows (partition-all 9 (map (comp read-string str) grid)) | |
cols (apply map (comp seq vector) rows) | |
squares (map | |
flatten | |
(partition-all | |
3 | |
(for [base (range 3) | |
row rows | |
range (take-nth | |
3 | |
(partition-all 3 (drop (* 3 base) row)))] | |
range)))] | |
(every? (fn [group] | |
(= (set (range 1 10)) | |
(set (map (comp read-string str) group)))) | |
(concat rows cols squares)))) |
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
(ns sudoku-validator.core-test | |
(:require [clojure.test :refer :all] | |
[sudoku-validator.core :refer :all])) | |
(deftest is-valid-solution-test | |
(testing "true if sudoku is valid" | |
(is (= true (is-valid-solution "835416927296857431417293658569134782123678549748529163652781394981345276374962815"))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment