Skip to content

Commit da92362

Browse files
authored
Merge pull request kodecocodes#828 from RandyTheDev/min-edit-distance-4.2
[Swift 4.2] Updated Minimum Edit Distance Playground for Swift 4.2
2 parents 3907f60 + 8683fb1 commit da92362

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

Minimum Edit Distance/MinimumEditDistance.playground/Contents.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11

22
// Minimum Edit Distance
3-
// last checked with Xcode 9.0b4
4-
#if swift(>=4.0)
5-
print("Hello, Swift 4!")
6-
#endif
73

84
extension String {
95

106
public func minimumEditDistance(other: String) -> Int {
11-
let m = self.characters.count
12-
let n = other.characters.count
7+
let m = self.count
8+
let n = other.count
139
var matrix = [[Int]](repeating: [Int](repeating: 0, count: n + 1), count: m + 1)
1410

1511
// initialize matrix
@@ -24,8 +20,8 @@ extension String {
2420
}
2521

2622
// compute Levenshtein distance
27-
for (i, selfChar) in self.characters.enumerated() {
28-
for (j, otherChar) in other.characters.enumerated() {
23+
for (i, selfChar) in self.enumerated() {
24+
for (j, otherChar) in other.enumerated() {
2925
if otherChar == selfChar {
3026
// substitution of equal symbols with cost 0
3127
matrix[i + 1][j + 1] = matrix[i][j]

Minimum Edit Distance/README.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ Then in each cell the minimum of the cost of insertion, deletion, or substitutio
3737

3838
```swift
3939
// compute Levenshtein distance
40-
for (i, selfChar) in self.characters.enumerated() {
41-
for (j, otherChar) in other.characters.enumerated() {
40+
for (i, selfChar) in self.enumerated() {
41+
for (j, otherChar) in other.enumerated() {
4242
if otherChar == selfChar {
4343
// substitution of equal symbols with cost 0
4444
matrix[i + 1][j + 1] = matrix[i][j]

0 commit comments

Comments
 (0)