Skip to content

Instantly share code, notes, and snippets.

@hiratara
Created June 9, 2009 13:47
Show Gist options
  • Save hiratara/126499 to your computer and use it in GitHub Desktop.
Save hiratara/126499 to your computer and use it in GitHub Desktop.
-- http://projecteuler.net/index.php?section=problems&id=4
intToPalindrome :: (Num a, Read a) => a -> a
intToPalindrome x = x * 1000 + ( read . reverse . show) x
palindromes = [intToPalindrome n | n <- [999,998..100] ]
is3by3 n = or $ map (\m -> and [n `mod` m == 0, is3 $ n `div` m]) [100 .. 999]
where is3 l = and [l >= 100, l < 1000]
answer = head $ filter is3by3 palindromes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment