Skip to content

Instantly share code, notes, and snippets.

@adeubank
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adeubank/939f3292a35d4a6cfa0a to your computer and use it in GitHub Desktop.
Save adeubank/939f3292a35d4a6cfa0a to your computer and use it in GitHub Desktop.
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