-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path111-crossword-puzzle.clj
More file actions
20 lines (20 loc) · 994 Bytes
/
111-crossword-puzzle.clj
File metadata and controls
20 lines (20 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
(fn [word board]
(letfn [(check-valid [word line]
(if (some #{\#} line)
(true? (some true? (map #(check-valid word %) (re-seq #"[^#]*" (apply str line)))))
(if (= (count word) (count line))
(if (and (seq word) (seq line))
(if (or (= \_ (first line)) (= (first word) (first line)))
(check-valid (next word) (next line))
false)
true)
false)))]
(let [non-space-board (map #(filter (fn [ch] (not= \space ch)) %) board)]
(true? (some true? (mapcat
(fn [ch]
(map
#(check-valid word %)
(filter
#(or (some #{ch} %) (every? #{\# \_} %))
(concat non-space-board (apply (partial map (fn [& coll] coll)) non-space-board)))))
word))))))