Project Euler #7 - 10001st prime I just finished Project Euler #7 in Swift, and since there is not any version yet on Code Review, I would like to have some comments on what I did to try to improve it.

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
What is the 10 001st prime number?

import Foundation

func isPrime(number:Int) -&gt; Bool {
    
    if number == 1 {
        return false
    }
    else if number &lt; 4 {
        return true
    }
    else if number % 2 == 0 {
        return false
    }
    else if number &lt; 9 {
        return true
    }
    else if number % 3 == 0 {
        return false
    }
    else {
        let maxPrime = Int(ceil(sqrt(Double(number))))
        
        for var i = 5; i &lt;= maxPrime; i += 6 {
            if number % i == 0  || number % (i + 2) == 0 {
                return false
            }
        }
    }
    
    return true
}

func getNumberForXthPrime(prime:Int) -&gt; Int {
    
    var xThPrime = prime - 1 // We skip the prime 2 with the += 2
    var number = 1
    
    while xThPrime &gt; 0 {
        
        number += 2
        if isPrime(number) {
            xThPrime--
        }
    }
    
    return number
}

func printTimeElapsedWhenRunningCode(operation:(xThPrime:Int) -&gt; Int) {
    let startTime = CFAbsoluteTimeGetCurrent()
    let number = operation(xThPrime: 10_001)
    println(number)
    let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
    println(&quot;Time elapsed : \(timeElapsed) s&quot;)
}

printTimeElapsedWhenRunningCode(getNumberForXthPrime)

The code executes in 0.0181439518928528 s.
for var i = 5; i &lt;= maxPrime; i += 6 {
    if number % i == 0  || number % (i + 2) == 0 {
        return false
    }
}


We can implement some Swift syntax here:

for i in stride(from:5 through:maxPrime by: 6) {
    if number % i == 0 || number % (i + 2) == 0 {
        return false
    }
}


I don't know how this would compare in terms of performance however.  I suspect it's the same or better however.