Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

close

  • Loading branch information...
commit 0e32a51af3e0be9370eb4634f263dcd3523eda2d 1 parent f0d54b2
@malcolmsparks authored
Showing with 18 additions and 7 deletions.
  1. +18 −7 src/boggle/core.clj
View
25 src/boggle/core.clj
@@ -9,7 +9,7 @@
(every? alphabet word))
(defn get-word-trie []
- (reduce #(assoc-in %1 (vec %2) {}) {} (filter is-valid-word? (line-seq (io/reader (io/file "/home/malcolm/src/boggle/src/boggle/small-dictionary"))))))
+ (reduce #(assoc-in %1 (vec %2) {}) {} (filter is-valid-word? (line-seq (io/reader (io/file "/home/malcolm/src/boggle/src/boggle/dictionary"))))))
(get-word-trie)
@@ -20,6 +20,7 @@
(identity board)
(defn get-board-entry [i j]
+ (println i " - " j)
(nth (nth board i) j)
)
@@ -30,19 +31,29 @@
(< (+ x (:i entry)) 8)
(>= (+ x (:i entry)) 0)
(< (+ y (:j entry)) 8)
- (>= (+ y (:j entry))) 0)]
+ (>= (+ y (:j entry)) 0))]
(get-board-entry (+ x (:i entry)) (+ y (:j entry)))
))
(defn search [board]
- (loop [remaining (get-word-trie), results [], pos (get-board-entry 0 0)]
- (if (empty? remaining)
- results
- (for [p (get-neighbors pos)
+ (letfn [(foo [visited , remaining , results , pos ]
+ (println visited results pos)
+ (if (empty? remaining)
+ results
+ (for [p (get-neighbors pos)
+ k (keys remaining)
+ :when (= (:char p) k)
]
- ))
+ (if (empty? (get remaining k))
+ (conj visited k)
+ (foo (conj visited k) (get remaining k) results p))
+ )))]
+ (foo [] (get-word-trie) [] (get-board-entry 0 0))
+
))
+(take 3 (search board))
+
Please sign in to comment.
Something went wrong with that request. Please try again.