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.39 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.38 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.37 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.36 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.35 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.34 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.33 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.32 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.31 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.30 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.29 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.28 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.27 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.26 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.25 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.24 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.23 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.22 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.21 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.20 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift