Stop That!
A mathcomic for Sophia Wood’s #mathober theme “truncate.” There must be a name for these primes.
Derek Orr says these are a thing! “Yes these are things!!! Right-truncatable primes: http://oeis.org/A024770″
seen from Japan
seen from Australia
seen from China
seen from United States

seen from Australia
seen from United States
seen from Thailand

seen from Malaysia
seen from China
seen from Mexico

seen from Bulgaria
seen from Japan
seen from Japan
seen from Germany
seen from China
seen from Switzerland
seen from Greece
seen from Türkiye

seen from Philippines
seen from Israel
Stop That!
A mathcomic for Sophia Wood’s #mathober theme “truncate.” There must be a name for these primes.
Derek Orr says these are a thing! “Yes these are things!!! Right-truncatable primes: http://oeis.org/A024770″
Problem 37
The number 3797 has an interesting property. Being prime itself, it is possible to continuously remove digits from left to right, and remain prime at each stage: 3797, 797, 97, and 7. Similarly we can work from right to left: 3797, 379, 37, and 3.
Find the sum of the only eleven primes that are both truncatable from left to right and right to left.
NOTE: 2, 3, 5, and 7 are not considered to be truncatable primes.
import Data.Char truncationL xs | length xs > 0 = xs:(truncationL $ tail xs) | otherwise = [] truncationR xs | length xs > 0 = xs:(truncationR $ take ((length xs)-1) xs) | otherwise = [] fromDigits = foldl addDigit 0 where addDigit num d = 10*num + d isPrime :: Int->Bool isPrime x = if x == 1 then False else null [y | y<-[2..floor (sqrt (fromIntegral x))], x `mod` y == 0] isTruncatablePrime n = all (\e -> isPrime $ fromDigits e) (truncationL $ map digitToInt $ show n) && all (\e -> isPrime $ fromDigits e) (truncationR $ map digitToInt $ show n) truncatablePrimes :: [Int] truncatablePrimes = [ x | x<-[11..(10^6)], isTruncatablePrime x] main = print(foldl (+) 0 truncatablePrimes)
List Operations so by definition will be slow, not too slow though...maybe this would be faster in CLISP, someone try it..