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.1.19 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.18 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.17 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.16 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.15 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.14 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.13 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.12 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.11 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.10 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.9 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.8 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.7 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.6 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.5 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.4 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.3 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.2 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.1 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.0 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift