Skip to content

Instantly share code, notes, and snippets.

@kidpollo
Last active August 29, 2015 14:20
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 kidpollo/61f4d57543ce8619901a to your computer and use it in GitHub Desktop.
Save kidpollo/61f4d57543ce8619901a to your computer and use it in GitHub Desktop.
(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))))
(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