Last active
August 29, 2015 14:22
-
-
Save LOZORD/56b99c6c8df7113a1ae0 to your computer and use it in GitHub Desktop.
Project Euler 37
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
import Data.List (nub, unfoldr) | |
-- FIXME | |
primeItr :: Integer -> Integer -> Bool | |
primeItr n i | |
| (i * i) > n = True | |
| otherwise = if (n `mod` i) == 0 | |
then False | |
else primeItr n (i + 1) | |
isPrime :: Integer -> Bool | |
isPrime n = primeItr n 2 -- 2-7 primes do not count (n > 10) | |
truncL :: Integer -> [Integer] | |
truncL n = nub $ map (\(k, s) -> read (drop k s)) (pairs) | |
where str = show n | |
strs = take (length str) (repeat str) | |
pairs = zip [0..] strs | |
truncR :: Integer -> [Integer] | |
truncR n = unfoldr (\b -> if (b == 0) then Nothing else Just(b, b `div` 10)) n | |
isTruncL :: Integer -> Bool | |
isTruncL n = all isPrime lTruncations | |
where lTruncations = truncL n | |
isTruncR :: Integer -> Bool | |
isTruncR n = all isPrime rTruncations | |
where rTruncations = truncR n | |
isTrunc :: Integer -> Bool | |
isTrunc n = (isTruncR n) && (isTruncL n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment