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