Skip to content

Instantly share code, notes, and snippets.

@omartell
Created January 16, 2018 23:42
Show Gist options
  • Save omartell/382b64acdebbc502ebcfc6d3c35b4971 to your computer and use it in GitHub Desktop.
Save omartell/382b64acdebbc502ebcfc6d3c35b4971 to your computer and use it in GitHub Desktop.
Sudoku Check
(defn sudokuCheck [rows]
(let [digits (set (range 1 10))
all-digits? (fn [col]
(every? (comp empty? #(clojure.set/difference digits (set %)))
col))
columns (for [index (range 0 9)]
(for [row rows]
(get row index)))
squares (for [gx (partition 3 (range 0 9))
gy (partition 3 (range 0 9))]
(for [x gx
y gy]
(get-in rows [x y])))]
(and (all-digits? rows)
(all-digits? columns)
(all-digits? squares))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment