Sha256: 1c66c65a7f4ec972e28f437c988a3011a5f656d39fa3c9547975ae12e4535b74

Contents?: true

Size: 604 Bytes

Versions: 139

Compression:

Stored size: 604 Bytes

Contents

struct SumOfMultiples {

    static func toLimit(_ limit: Int, inMultiples: [Int]) -> Int {
        guard limit > 0 else { return 0 }
        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

139 entries across 139 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.179 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.178 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.177 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.176 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.175 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.174 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.173 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.172 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.171 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.170 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.169 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.167 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.166 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.165 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.164 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.163 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.162 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.161 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift
trackler-2.2.1.160 tracks/swift/exercises/sum-of-multiples/Sources/SumOfMultiplesExample.swift