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.0.5.11 tracks/swift/exercises/hamming/HammingExample.swift
trackler-2.0.5.10 tracks/swift/exercises/hamming/HammingExample.swift
trackler-2.0.5.9 tracks/swift/exercises/hamming/HammingExample.swift
trackler-2.0.5.8 tracks/swift/exercises/hamming/HammingExample.swift
trackler-2.0.5.7 tracks/swift/exercises/hamming/HammingExample.swift
trackler-2.0.5.6 tracks/swift/exercises/hamming/HammingExample.swift
trackler-2.0.5.5 tracks/swift/exercises/hamming/HammingExample.swift
trackler-2.0.5.4 tracks/swift/exercises/hamming/HammingExample.swift
trackler-2.0.5.3 tracks/swift/exercises/hamming/HammingExample.swift
trackler-2.0.5.2 tracks/swift/exercises/hamming/HammingExample.swift
trackler-2.0.5.1 tracks/swift/exercises/hamming/HammingExample.swift
trackler-2.0.5.0 tracks/swift/exercises/hamming/HammingExample.swift
trackler-2.0.4.0 tracks/swift/exercises/hamming/HammingExample.swift
trackler-2.0.3.9 tracks/swift/exercises/hamming/HammingExample.swift
trackler-2.0.3.8 tracks/swift/exercises/hamming/HammingExample.swift
trackler-2.0.3.7 tracks/swift/exercises/hamming/HammingExample.swift
trackler-2.0.3.6 tracks/swift/exercises/hamming/HammingExample.swift
trackler-2.0.3.5 tracks/swift/exercises/hamming/HammingExample.swift
trackler-2.0.3.4 tracks/swift/exercises/hamming/HammingExample.swift
trackler-2.0.3.3 tracks/swift/exercises/hamming/HammingExample.swift