Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial #430

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ pom.xml
.lein-deps-sum
.lein-failures
.lein-plugins
.lein-repl-history
/.idea

1 change: 1 addition & 0 deletions .nrepl-port
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
39150
97 changes: 80 additions & 17 deletions src/sudoku.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,119 @@

(def board identity)

(def all-values #{1 2 3 4 5 6 7 8 9})

(defn value-at [board coord]
nil)
(get-in board coord))

(defn has-value? [board coord]
nil)
(not (= (get-in board coord) 0)))

(defn row-values [board coord]
nil)
(set (get board (first coord))))

(defn col-values [board coord]
nil)
(reduce
(fn [a b]
(conj a (value-at board [b (second coord)])))
#{}
(range 9)))

(defn coord-pairs [coords]
nil)
(for [y coords
x coords]
[y x]))

(defn top-left-corner [coord]
(vector
(* 3 (int (/ (first coord) 3)))
(* 3 (int (/ (second coord) 3)))))

(defn coord-pairs-in-block [coord]
(map
(fn [coord-pair]
[(+ (first coord-pair) (first (top-left-corner coord)))
(+ (second coord-pair) (second (top-left-corner coord)))])
(coord-pairs [0 1 2])))

(defn block-values [board coord]
nil)
(reduce
(fn [result-set coords-vec]
(conj result-set (value-at board coords-vec)))
#{}
(coord-pairs-in-block coord)))

(defn valid-values-for [board coord]
nil)
(if (has-value? board coord)
#{}
(set/difference
all-values
(set/union
(block-values board coord)
(row-values board coord)
(col-values board coord)))))

(defn filled? [board]
nil)
(empty?
(set/difference
(set
(for [y (range 9) x (range 9)]
(value-at board [y x])))
all-values)))

(defn rows [board]
nil)
(into []
(for [y (range 9)]
(set (row-values board [y 0])))))

(defn valid-rows? [board]
nil)
(every?
(fn [row]
(empty? (set/difference all-values row)))
(rows board)))


(defn cols [board]
nil)
(into []
(for [x (range 9)]
(set (col-values board [0 x])))))

(defn valid-cols? [board]
nil)
(every?
(fn [col]
(empty? (set/difference all-values col)))
(cols board)))

(defn blocks [board]
nil)
(into []
(for [y (range 3)
x (range 3)]
(set
(block-values
board
[(* 3 y) (* 3 x)])))))

(defn valid-blocks? [board]
nil)
(every?
(fn [block]
(empty? (set/difference all-values block)))
(blocks board)))

(defn valid-solution? [board]
nil)
(and
(valid-rows? board)
(valid-cols? board)
(valid-blocks? board)))

(defn set-value-at [board coord new-value]
nil)
(assoc-in board coord new-value))

(defn find-empty-point [board]
nil)
(loop [all-coords (coord-pairs (range 9))]
(when all-coords
(if (zero? (value-at board (first all-coords)))
(first all-coords)
(recur (next all-coords))))))

(defn solve [board]
nil)
69 changes: 69 additions & 0 deletions sudoku.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<module cursive.leiningen.project.LeiningenProjectsManager.displayName="sudoku:1.0.0-SNAPSHOT" cursive.leiningen.project.LeiningenProjectsManager.isLeinModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/classes" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/resources" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/dev-resources" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Leiningen: bultitude:0.1.7" level="project" />
<orderEntry type="library" name="Leiningen: classlojure:0.6.6" level="project" />
<orderEntry type="library" name="Leiningen: clojure-complete:0.2.4" level="project" />
<orderEntry type="library" name="Leiningen: colorize:0.1.1" level="project" />
<orderEntry type="library" name="Leiningen: com.cemerick/pomegranate:0.0.13" level="project" />
<orderEntry type="library" name="Leiningen: commons-codec:1.6" level="project" />
<orderEntry type="library" name="Leiningen: commons-io:2.0.1" level="project" />
<orderEntry type="library" name="Leiningen: commons-logging:1.1.1" level="project" />
<orderEntry type="library" name="Leiningen: gui-diff:0.3.9" level="project" />
<orderEntry type="library" name="Leiningen: iloveponies.tests/sudoku:0.1.0-SNAPSHOT" level="project" />
<orderEntry type="library" name="Leiningen: joda-time:2.0" level="project" />
<orderEntry type="library" name="Leiningen: leiningen-core:2.0.0-preview10" level="project" />
<orderEntry type="library" name="Leiningen: midje-grader:0.1.0-SNAPSHOT" level="project" />
<orderEntry type="library" name="Leiningen: midje:1.5.1" level="project" />
<orderEntry type="library" name="Leiningen: ordered:1.2.0" level="project" />
<orderEntry type="library" name="Leiningen: org.apache.httpcomponents/httpclient:4.1.2" level="project" />
<orderEntry type="library" name="Leiningen: org.apache.httpcomponents/httpcore:4.1.2" level="project" />
<orderEntry type="library" name="Leiningen: org.apache.maven.wagon/wagon-http-shared4:2.2" level="project" />
<orderEntry type="library" name="Leiningen: org.apache.maven.wagon/wagon-http:2.2" level="project" />
<orderEntry type="library" name="Leiningen: org.apache.maven.wagon/wagon-provider-api:2.2" level="project" />
<orderEntry type="library" name="Leiningen: org.apache.maven/maven-aether-provider:3.0.4" level="project" />
<orderEntry type="library" name="Leiningen: org.apache.maven/maven-model-builder:3.0.4" level="project" />
<orderEntry type="library" name="Leiningen: org.apache.maven/maven-model:3.0.4" level="project" />
<orderEntry type="library" name="Leiningen: org.apache.maven/maven-repository-metadata:3.0.4" level="project" />
<orderEntry type="library" name="Leiningen: org.clojure/algo.monads:0.1.0" level="project" />
<orderEntry type="library" name="Leiningen: org.clojure/clojure:1.5.1" level="project" />
<orderEntry type="library" name="Leiningen: org.clojure/core.incubator:0.1.0" level="project" />
<orderEntry type="library" name="Leiningen: org.clojure/core.unify:0.5.2" level="project" />
<orderEntry type="library" name="Leiningen: org.clojure/data.json:0.2.3" level="project" />
<orderEntry type="library" name="Leiningen: org.clojure/math.combinatorics:0.0.1" level="project" />
<orderEntry type="library" name="Leiningen: org.clojure/tools.macro:0.1.1" level="project" />
<orderEntry type="library" name="Leiningen: org.clojure/tools.namespace:0.2.2" level="project" />
<orderEntry type="library" name="Leiningen: org.clojure/tools.nrepl:0.2.12" level="project" />
<orderEntry type="library" name="Leiningen: org.codehaus.plexus/plexus-classworlds:2.4" level="project" />
<orderEntry type="library" name="Leiningen: org.codehaus.plexus/plexus-component-annotations:1.5.5" level="project" />
<orderEntry type="library" name="Leiningen: org.codehaus.plexus/plexus-interpolation:1.14" level="project" />
<orderEntry type="library" name="Leiningen: org.codehaus.plexus/plexus-utils:2.0.7" level="project" />
<orderEntry type="library" name="Leiningen: org.jsoup/jsoup:1.6.1" level="project" />
<orderEntry type="library" name="Leiningen: org.sonatype.aether/aether-api:1.13.1" level="project" />
<orderEntry type="library" name="Leiningen: org.sonatype.aether/aether-connector-file:1.13.1" level="project" />
<orderEntry type="library" name="Leiningen: org.sonatype.aether/aether-connector-wagon:1.13.1" level="project" />
<orderEntry type="library" name="Leiningen: org.sonatype.aether/aether-impl:1.13.1" level="project" />
<orderEntry type="library" name="Leiningen: org.sonatype.aether/aether-spi:1.13.1" level="project" />
<orderEntry type="library" name="Leiningen: org.sonatype.aether/aether-util:1.13.1" level="project" />
<orderEntry type="library" name="Leiningen: org.sonatype.sisu/sisu-guice:3.0.3:no_aop" level="project" />
<orderEntry type="library" name="Leiningen: org.sonatype.sisu/sisu-inject-bean:2.2.3" level="project" />
<orderEntry type="library" name="Leiningen: org.sonatype.sisu/sisu-inject-plexus:2.2.3" level="project" />
<orderEntry type="library" name="Leiningen: robert/hooke:1.1.2" level="project" />
<orderEntry type="library" name="Leiningen: slingshot:0.10.3" level="project" />
<orderEntry type="library" name="Leiningen: swiss-arrows:0.1.0" level="project" />
<orderEntry type="library" name="Leiningen: useful:0.8.3-alpha8" level="project" />
<orderEntry type="library" name="Leiningen: utilize:0.2.3" level="project" />
</component>
</module>