module Problem37 where

import Prime

main :: IO ()
main = print . sum . take 11 . filter truncablePrime $ [11 ..]

truncablePrime :: Int -> Bool
truncablePrime n
    | n < 10    = isPrimeNaive n
    | otherwise = isPrimeNaive n && leftTruncablePrime n && rightTruncablePrime n

leftTruncablePrime :: Int -> Bool
leftTruncablePrime n
    | n < 10    = isPrimeNaive n
    | otherwise = isPrimeNaive n && (leftTruncablePrime . read . tail . show $ n)

rightTruncablePrime :: Int -> Bool
rightTruncablePrime n
    | n < 10    = isPrimeNaive n
    | otherwise = isPrimeNaive n && rightTruncablePrime (n `div` 10)
