Skip to content

Instantly share code, notes, and snippets.

@cacharle
Created September 4, 2019 18:19
Show Gist options
  • Save cacharle/8aadb518c0511456a0a693459d7d1743 to your computer and use it in GitHub Desktop.
Save cacharle/8aadb518c0511456a0a693459d7d1743 to your computer and use it in GitHub Desktop.
isPrime :: Int -> Bool
isPrime 2 = True
isPrime 3 = True
isPrime x
| x < 2 = False
| x `mod` 2 == 0 || x `mod` 3 == 0 = False
| otherwise = divCheck 5
where divCheck d
| d * d > x = True
| x `mod` d == 0 || x `mod` (d + 2) == 0 = False
| otherwise = divCheck (d + 6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment