Created
June 12, 2019 15:59
-
-
Save vicxruiz/96ab64fe517e0f0d001dd56291f2ec74 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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