Skip to content

Instantly share code, notes, and snippets.

@vicxruiz
Created June 12, 2019 15:59
Show Gist options
  • Save vicxruiz/96ab64fe517e0f0d001dd56291f2ec74 to your computer and use it in GitHub Desktop.
Save vicxruiz/96ab64fe517e0f0d001dd56291f2ec74 to your computer and use it in GitHub Desktop.
func isTwinPrime(_ number: Int) -> Bool {
if number > 1 && !(2..<number).contains { number % $0 == 0 } {
let lowerDifference = number - 2
let higherDifference = number + 2
if lowerDifference > 1 && !(2..<lowerDifference).contains { lowerDifference % $0 == 0 } {
return true
}
if higherDifference > 1 && !(2..<higherDifference).contains { higherDifference % $0 == 0 } {
return true
}
}
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment