#!/usr/bin/env runhaskell import Data.ByteString.Lazy.Char8 as BS hiding (filter,take,concat,map,drop,length) import Data.Char main = validate_check_digits "4910099710741" validate_check_digits :: [Char] -> IO () validate_check_digits digits = do digits <- readF putStrLn show $ validate_check_even_digits digits * 3 + validate_check_odd_digits digits validate_check_even_digits :: [Char] -> Int validate_check_even_digits [] = 0 validate_check_even_digits (x1:(_:(x2:(_:xs)))) = (digitToInt x1) + (digitToInt x2) + validate_check_even_digits xs validate_check_odd_digits :: [Char] -> Int validate_check_odd_digits [] = 0 validate_check_odd_digits (_:odd_digits) = validate_check_even_digits odd_digits readF :: String -> IO BS.ByteString readF "-" = BS.getContents readF f = BS.readFile f