Skip to content

Instantly share code, notes, and snippets.

@phasedchirp
Created August 23, 2016 22:01
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 phasedchirp/dc3e3841c4f035bb304f289a6837ff07 to your computer and use it in GitHub Desktop.
Save phasedchirp/dc3e3841c4f035bb304f289a6837ff07 to your computer and use it in GitHub Desktop.
import Data.List (nubBy)
primeList :: Integer -> [Integer]
primeList n = nubBy (\y x-> x`mod`y==0) [2..n]
-- primes = primeList 1000000
primes = primeList 100
rotations :: Integer -> [Integer]
rotations x = map read $ filter (\x -> head x /= '0') $ take l (iterate step (show x))
where l = length (show x)
step :: String -> String
step (x:xs) = xs ++ [x]
check :: Integer -> Bool
check x = x `elem` (takeWhile (<= x) primes)
checkAll :: [Integer] -> Bool
checkAll x = and $ map check x
checkRotations :: Integer -> Bool
checkRotations x = checkAll $ rotations x
circular = filter checkRotations primes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment