Skip to content

Instantly share code, notes, and snippets.

@2GMon
Created August 29, 2012 02:03
Show Gist options
  • Save 2GMon/3506066 to your computer and use it in GitHub Desktop.
Save 2GMon/3506066 to your computer and use it in GitHub Desktop.
Project Euler : Problem 38
-- Project Euler : Problem 38
import Data.List
isPandigital :: Maybe String -> Bool
isPandigital Nothing = False
isPandigital (Just x) = all (`elem` x) ['1'..'9']
catProduct :: Int -> Maybe String
catProduct x = find (\x -> (length x) == 9) $ map (product x) [2..9]
where product x n = foldl (\acc y -> acc ++ y) "" $ map show $ map (* x) [1..n]
main = print $ last $ sort $ filter isPandigital $ map catProduct [1..9999]
-- Just "932718654"
-- ./dailycoding38 0.08s user 0.00s system 95% cpu 0.084 total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment