Skip to content

Instantly share code, notes, and snippets.

@v0idpwn
Created Mar 25, 2018
Embed
What would you like to do?
-- 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