Sha256: b379c34394cf0934298fcb833544579ceddc2e10e6cae129cac946ede4d54e5b

Contents?: true

Size: 562 Bytes

Versions: 49

Compression:

Stored size: 562 Bytes

Contents

struct SumOfMultiples {

    static func toLimit(_ limit: Int, inMultiples: [Int]) -> Int {
        var multiples = Set(inMultiples)

        if let indexOfZero = multiples.index(of: 0) {
            multiples.remove(at: indexOfZero)
        }

        var itemToReturn = 0

        for each in 1..<limit {
            var lastAdded = 0
            for multiple in multiples where ((each % multiple == 0) && (lastAdded != each)) {
                itemToReturn += each
                lastAdded = each
            }
        }

        return itemToReturn
    }
}

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
trackler-2.2.0.6 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.0.5 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.0.4 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.0.3 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.0.2 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.0.1 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.0.0 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.1.0.55 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.1.0.54 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift