Sha256: 78ec9d2d89fe734d87b35f470a53c2e01aa65fbaa9078882b6406d6b484fd647
Contents?: true
Size: 772 Bytes
Versions: 130
Compression:
Stored size: 772 Bytes
Contents
struct Sieve { var value: Int = 0 init(_ num: Int) { self.value = num } var primes: [Int] {return primesFunc(self.value ) } func primesFunc(_ limit: Int) -> [Int] { if limit < 2 { return []} else { let tempArray = Array(2...limit) return tempArray.filter {Sieve.onlyDivisorSelf($0)} } } static func onlyDivisorSelf( _ number: Int) -> Bool { var number = number var primes = [Int]() var divisor: Int = 2 while number > 1 { while number % divisor == 0 { primes.append(divisor) number /= divisor } divisor += 1 } if primes.count == 1 {return true} else {return false} } }
Version data entries
130 entries across 130 versions & 1 rubygems