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.6.32 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.0.6.31 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.0.6.30 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.0.6.29 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.0.6.28 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.0.6.27 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.0.6.26 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.0.6.25 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.0.6.24 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.0.6.23 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.0.6.22 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.0.6.21 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.0.6.20 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.0.6.19 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.0.6.18 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.0.6.17 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.0.6.16 tracks/swift/exercises/hamming/Sources/HammingExample.swift
trackler-2.0.6.15 tracks/swift/exercises/hamming/HammingExample.swift
trackler-2.0.6.14 tracks/swift/exercises/hamming/HammingExample.swift
trackler-2.0.6.13 tracks/swift/exercises/hamming/HammingExample.swift