We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent cb22f0a commit 5988e56Copy full SHA for 5988e56
1 file changed
back5/src/back5/spell.clj
@@ -21,15 +21,25 @@
21
(for [x (range (.length word))]
22
[(without-char word x) 1])))
23
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
34
(defn edits1 [word]
- (let [s (for [i (range (inc (count word)))] (split-at i word))
35
+ (let [s (split-word word)
36
deletes (deletes word)
37
transposes (into {}
38
(for [[a,b] s :when (> (count b) 1)]
39
[(apply str
40
(concat a [(second b)] [(first b)] (drop 2 b)))
41
1]))
- replaces []
42
+ replaces (replaces s)
43
inserts [] ]
44
(merge-with max deletes transposes replaces inserts)))
45
0 commit comments