Skip to content

Commit 12be302

Browse files
committed
Clean up integration within edits1
1 parent 640c793 commit 12be302

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

back5/src/back5/spell.clj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,21 @@
1717
(str (apply str (take i word)) (apply str (drop (inc i) word))))
1818

1919
(defn deletes [word]
20+
(into {}
2021
(for [x (range (.length word))]
21-
{(without-char word x) 1}))
22+
[(without-char word x) 1])))
2223

2324
(defn edits1 [word]
2425
(let [s (for [i (range (inc (count word)))] (split-at i word))
2526
deletes (deletes word)
26-
transposes (for [[a,b] s :when (> (count b) 1)]
27-
(concat a [(second b)] [(first b)] (drop 2 b)))
27+
transposes (into {}
28+
(for [[a,b] s :when (> (count b) 1)]
29+
[(apply str
30+
(concat a [(second b)] [(first b)] (drop 2 b)))
31+
1]))
2832
replaces []
2933
inserts [] ]
30-
(zipmap (concat deletes transposes replaces inserts) (repeat 1))))
34+
(merge-with max deletes transposes replaces inserts)))
3135

3236

3337
(defn edits1-replaces [a c b]

0 commit comments

Comments
 (0)