Skip to content

Commit

Permalink
Oh dear!!
Browse files Browse the repository at this point in the history
  • Loading branch information
malcolmsparks committed Feb 28, 2012
1 parent a61a096 commit f0d54b2
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/boggle/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,48 @@

(def alphabet (apply hash-set (map char (range (int \a) (inc (int \z))))))

(def alphas (map char (range (int \a) (inc (int \z)))))

(defn is-valid-word? [word]
(every? alphabet word))

(reduce #(assoc-in %1 (vec %2) {}) {} (filter is-valid-word? (line-seq (io/reader (io/file "/home/malcolm/src/boggle/src/boggle/small-dictionary")))))
(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"))))))

(get-word-trie)

(defn get-row [] (apply vector (for [i (range 8)] {:i i :char (rand-nth alphas)})))

(def board (apply vector (for [j (range 8)] (map (partial merge {:j j}) (get-row)))))

(identity board)

(defn get-board-entry [i j]
(nth (nth board i) j)
)

(defn get-neighbors [entry]
(for [x [-1 0 1]
y [-1 0 1]
:when (and (not (and (= 0 x) (= 0 y)))
(< (+ x (:i entry)) 8)
(>= (+ x (:i entry)) 0)
(< (+ y (:j entry)) 8)
(>= (+ 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)
]
))
))






Expand Down

0 comments on commit f0d54b2

Please sign in to comment.