Created
January 9, 2014 12:12
-
-
Save iseebi/8333173 to your computer and use it in GitHub Desktop.
すごいHaskell読書会 #15 - 練習問題復習 @ #1
This file contains 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
scanDigits :: Int -> Int -> (String, String) | |
scanDigits a x = (take a $ show x, drop a $ show x) | |
calcTuple :: (String, String) -> Int | |
calcTuple (x, y) = (read x) + (read y) | |
calc :: Int -> (Int, Int) | |
calc x = (calcTuple (scanDigits 1 x), calcTuple (scanDigits 2 x)) | |
checkCalc :: Int -> (Int, Int) -> Bool | |
checkCalc x (y, z) = ((x `mod` y) == 0) && ((x `mod` z) == 0) | |
check :: Int -> Bool | |
check x = checkCalc x $ calc x | |
main = do | |
print $ take 4 $ filter (\x -> (x `mod` 10) /= 0) $ filter check [100..999] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment