Skip to content

Instantly share code, notes, and snippets.

@ChrisBuchholz
Created December 10, 2012 13:40
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 ChrisBuchholz/4250615 to your computer and use it in GitHub Desktop.
Save ChrisBuchholz/4250615 to your computer and use it in GitHub Desktop.
import Data.Char
prime n
| n < 2 = False
| n == 2 = True
| null [x | x <- [2..(floor . sqrt $ fromIntegral n)], n `mod` x == 0] = True
| otherwise = False
truncateListRight xs = take (length xs) $ iterate init xs
truncateListLeft xs = take (length xs) $ iterate (drop 1) xs
truncateSteps n = truncateListLeft nn ++ truncateListRight nn
where nn = map digitToInt $ show n
truncatablePrime n = and $ map (\ns -> prime $ foldl (\x y -> 10 * x + y) 0 ns) $ truncateSteps n
main = print $ sum $ take 11 $ [n | n <- [9,11..], truncatablePrime n]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment