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.5.13 tracks/swift/exercises/sieve/SieveExample.swift
trackler-2.0.5.12 tracks/swift/exercises/sieve/SieveExample.swift
trackler-2.0.5.11 tracks/swift/exercises/sieve/SieveExample.swift
trackler-2.0.5.10 tracks/swift/exercises/sieve/SieveExample.swift
trackler-2.0.5.9 tracks/swift/exercises/sieve/SieveExample.swift
trackler-2.0.5.8 tracks/swift/exercises/sieve/SieveExample.swift
trackler-2.0.5.7 tracks/swift/exercises/sieve/SieveExample.swift
trackler-2.0.5.6 tracks/swift/exercises/sieve/SieveExample.swift
trackler-2.0.5.5 tracks/swift/exercises/sieve/SieveExample.swift
trackler-2.0.5.4 tracks/swift/exercises/sieve/SieveExample.swift
trackler-2.0.5.3 tracks/swift/exercises/sieve/SieveExample.swift
trackler-2.0.5.2 tracks/swift/exercises/sieve/SieveExample.swift
trackler-2.0.5.1 tracks/swift/exercises/sieve/SieveExample.swift
trackler-2.0.5.0 tracks/swift/exercises/sieve/SieveExample.swift
trackler-2.0.4.0 tracks/swift/exercises/sieve/SieveExample.swift
trackler-2.0.3.9 tracks/swift/exercises/sieve/SieveExample.swift
trackler-2.0.3.8 tracks/swift/exercises/sieve/SieveExample.swift
trackler-2.0.3.7 tracks/swift/exercises/sieve/SieveExample.swift
trackler-2.0.3.6 tracks/swift/exercises/sieve/SieveExample.swift
trackler-2.0.3.5 tracks/swift/exercises/sieve/SieveExample.swift