-
Notifications
You must be signed in to change notification settings - Fork 0
/
37.hs
21 lines (20 loc) · 760 Bytes
/
37.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import Math.NumberTheory.Prime (primes, isPrime)
import Data.Digits
import Data.List
main = putStrLn $ show $ sum $ take 11 truncatable_primes
where
truncatable_primes = [prime | prime <- primes, isTruncatable prime]
where
isTruncatable n
| n <= 10 = False
| otherwise = all isPrime (numbersToTest n)
numbersToTest n = (foldl (++) [] list_of_permutations) ++ [n]
where
list_of_permutations = map (permutation digits_of_n) [1..pred $ length digits_of_n]
digits_of_n = digits 10 n
permutation [] _ = []
permutation xs@(x:[]) _ = xs
permutation xs n = [firstNumber,secondNumber]
where
firstNumber = unDigits 10 (inits xs !! n)
secondNumber = unDigits 10 (reverse (tails xs) !! n)