Sha256: 84bfbf391b076b8db7b93e6c6921f2524f1da0a33d92bdc1ffbc12f802c56198

Contents?: true

Size: 780 Bytes

Versions: 266

Compression:

Stored size: 780 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

266 entries across 266 versions & 1 rubygems

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