Created
June 26, 2014 12:12
-
-
Save lnicola/135b0e0901c1ea7a0ce6 to your computer and use it in GitHub Desktop.
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
| module Main (main) where | |
| import Control.Parallel.Strategies | |
| import Control.Monad | |
| import Data.Char | |
| solve s (x : xs) = (solve x xs >>= \r -> [s + r, s - r]) ++ solve (10 * s + x) xs | |
| solve s _ = [s] | |
| ugly x = x `mod` 2 == 0 || x `mod` 3 == 0 || x `mod` 5 == 0 || x `mod` 7 == 0 | |
| ans d = let s = map (\x -> toInteger $ ord x - ord '0') d in | |
| length $ filter id $ map ugly $ solve (head s) $ tail s | |
| main = putStr =<< liftM (unlines . parMap rnf (\x -> "Case #" ++ (show $ fst x) ++ ": " ++ show (ans (snd x))) . zip [1..] . tail . lines) getContents |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment