Created
August 29, 2012 02:03
-
-
Save 2GMon/3506066 to your computer and use it in GitHub Desktop.
Project Euler : Problem 38
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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