Skip to content

Instantly share code, notes, and snippets.

@v0idpwn
Created March 25, 2018 22:31
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 v0idpwn/b2db1b9a729ff560be878bdc4b6af46a to your computer and use it in GitHub Desktop.
Save v0idpwn/b2db1b9a729ff560be878bdc4b6af46a to your computer and use it in GitHub Desktop.
-- primality test written in haskell
-- github.com/v0idpwn
multipliers = [y | k <- [1..], y <- [(6*k)-1, (6*k)+1]]
used n = [2,3] ++ takeWhile(< sqrt n) multipliers
check_div :: Int -> Int -> Bool
check_div k p
| mod k p == 0 = True
| otherwise = False
primality_test :: Int -> [Bool]
primality_test x = map (check_div x) (used x)
check :: [Bool] -> Bool
check xs
| or xs = False
| otherwise = True
main = print (check (primality test 79))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment