Sha256: 4e3d9f8795b698625716e291a8e53697ff4dabd2746501db0b3b515086c3462e

Contents?: true

Size: 659 Bytes

Versions: 208

Compression:

Stored size: 659 Bytes

Contents

struct Hamming {
    static func compute(_ input: String, against: String) -> Int? {
        var differences = 0

        let char1 = convertStringToArray(input)
        let char2 = convertStringToArray(against)

        if char1.count != char2.count { return nil }
        for i in 0..<char1.count {
            if char1[i] != char2[i] {
                differences += 1
            }
        }
        return differences
    }

}

private func convertStringToArray(_ input: String) -> [Character] {
    var characterArray: [Character] = []

    for character in input.characters {
        characterArray.append(character)
    }

    return characterArray
}

Version data entries

208 entries across 208 versions & 1 rubygems

Version Path
trackler-2.1.0.53 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.1.0.52 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.1.0.51 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.1.0.50 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.1.0.49 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.1.0.48 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.1.0.47 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.1.0.46 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.1.0.45 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.1.0.44 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.1.0.43 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.1.0.42 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.1.0.41 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.1.0.40 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.1.0.39 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.1.0.38 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.1.0.37 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.1.0.36 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.1.0.34 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.1.0.33 tracks/swift/exercises/hamming/Sources/HammingExample.swift