Skip to content

Commit 5988e56

Browse files
committed
Implement replaces, factor our split-word
1 parent cb22f0a commit 5988e56

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

back5/src/back5/spell.clj

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,25 @@
2121
(for [x (range (.length word))]
2222
[(without-char word x) 1])))
2323

24+
(defn replaces [s]
25+
(into {}
26+
(for [[a b] s
27+
:while (seq b)
28+
r alphabet]
29+
[(apply str (concat a [r] (rest b))) 1])))
30+
31+
(defn split-word [word]
32+
(for [i (range (inc (count word)))] (split-at i word)))
33+
2434
(defn edits1 [word]
25-
(let [s (for [i (range (inc (count word)))] (split-at i word))
35+
(let [s (split-word word)
2636
deletes (deletes word)
2737
transposes (into {}
2838
(for [[a,b] s :when (> (count b) 1)]
2939
[(apply str
3040
(concat a [(second b)] [(first b)] (drop 2 b)))
3141
1]))
32-
replaces []
42+
replaces (replaces s)
3343
inserts [] ]
3444
(merge-with max deletes transposes replaces inserts)))
3545

0 commit comments

Comments
 (0)