Skip to content

Instantly share code, notes, and snippets.

@jlouis
Created November 1, 2009 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlouis/223763 to your computer and use it in GitHub Desktop.
Save jlouis/223763 to your computer and use it in GitHub Desktop.
import Data.List
numbers = [1..10^6]
convRadix :: (Integral b) => b -> b -> [b]
convRadix n =
unfoldr (\b -> if b == 0 then Nothing else Just (b `mod` n, b `div` n))
isPalindrome10 n = sn == (reverse sn)
where sn = show n
isPalindrome2 n = sn == (reverse sn)
where sn = concatMap show $ convRadix 2 n
check ns = sum $ filter (\n -> isPalindrome10 n && isPalindrome2 n) ns
main =
do putStrLn $ show $ check numbers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment