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

Version Path
trackler-2.0.8.9 tracks/swift/exercises/sieve/Sources/SieveExample.swift
trackler-2.0.8.8 tracks/swift/exercises/sieve/Sources/SieveExample.swift
trackler-2.0.8.7 tracks/swift/exercises/sieve/Sources/SieveExample.swift
trackler-2.0.8.6 tracks/swift/exercises/sieve/Sources/SieveExample.swift
trackler-2.0.8.5 tracks/swift/exercises/sieve/Sources/SieveExample.swift
trackler-2.0.8.4 tracks/swift/exercises/sieve/Sources/SieveExample.swift
trackler-2.0.8.3 tracks/swift/exercises/sieve/Sources/SieveExample.swift
trackler-2.0.8.2 tracks/swift/exercises/sieve/Sources/SieveExample.swift
trackler-2.0.8.1 tracks/swift/exercises/sieve/Sources/SieveExample.swift
trackler-2.0.7.0 tracks/swift/exercises/sieve/Sources/SieveExample.swift
trackler-2.0.6.44 tracks/swift/exercises/sieve/Sources/SieveExample.swift
trackler-2.0.6.43 tracks/swift/exercises/sieve/Sources/SieveExample.swift
trackler-2.0.6.42 tracks/swift/exercises/sieve/Sources/SieveExample.swift
trackler-2.0.6.41 tracks/swift/exercises/sieve/Sources/SieveExample.swift
trackler-2.0.6.40 tracks/swift/exercises/sieve/Sources/SieveExample.swift
trackler-2.0.6.39 tracks/swift/exercises/sieve/Sources/SieveExample.swift
trackler-2.0.6.38 tracks/swift/exercises/sieve/Sources/SieveExample.swift
trackler-2.0.6.37 tracks/swift/exercises/sieve/Sources/SieveExample.swift
trackler-2.0.6.36 tracks/swift/exercises/sieve/Sources/SieveExample.swift
trackler-2.0.6.35 tracks/swift/exercises/sieve/Sources/SieveExample.swift