Skip to content

Instantly share code, notes, and snippets.

@iseebi
Created January 9, 2014 12:12
Show Gist options
  • Save iseebi/8333173 to your computer and use it in GitHub Desktop.
Save iseebi/8333173 to your computer and use it in GitHub Desktop.
すごいHaskell読書会 #15 - 練習問題復習 @ #1
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