aboutsummaryrefslogtreecommitdiff
path: root/challenge-164/alexander-pankoff/haskell/ch-1.hs
blob: 897ebbcf7b6f4c1e079492b401fa6acc99c0b5fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
module Main where

import Control.Monad (liftM2)

main :: IO ()
main = print $ primePalindromes [1 .. 1000]

primePalindromes :: [Int] -> [Int]
primePalindromes = filter (liftM2 (&&) isPalindrome isPrime)

isPrime :: Int -> Bool
isPrime n = n > 1 && null [x | x <- [2 .. (isqrt n)], n `mod` x == 0]

isPalindrome :: Int -> Bool
isPalindrome = liftM2 (==) show (reverse . show)

isqrt :: Int -> Int
isqrt = floor . sqrt . fromIntegral