Created
January 16, 2015 13:28
-
-
Save antekone/f80dd4583c6672439124 to your computer and use it in GitHub Desktop.
prime generation by trial division testing
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
checkd :: [Int] -> Int -> Int | |
checkd [] n = n | |
checkd (prime:primes) n = | |
if (elem n primes || n `mod` prime == 0) then | |
prime | |
else | |
checkd primes n | |
preplist :: [Int] -> Int -> [Int] | |
preplist curlist n = filter (\ x -> x < (n `div` 2 + 1)) curlist | |
gen :: Int -> Int -> [Int] -> [Int] | |
gen a b xs = | |
if a <= b then gen (a + 2) b newxs else xs | |
where | |
prime = checkd (preplist xs a) a | |
newxs = if prime == a then | |
xs ++ [prime] | |
else | |
xs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment