Skip to content

Instantly share code, notes, and snippets.

@adeubank

adeubank/isPrime.swift

Last active Aug 29, 2015
Embed
What would you like to do?
Adds an extension to the Int class to tell return whether an integer is prime or not
extension Int {
func isPrime() -> Bool {
if (self == 1) { return false }
if (self == 2) { return true }
var sqr = Int(sqrt(Float(self))) + 1
for i in 2...sqr {
if self % i == 0 {
return false
}
}
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment