Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- readInt :: String -> Int
- readInt = read
- splitBy :: Char -> String -> [String]
- splitBy _ "" = []
- splitBy ch s = let (l, s') = break (== ch) s
- in l : case s' of
- [] -> []
- (_:s'') -> splitBy ch s''
- hasDelimiter :: String -> Bool
- hasDelimiter text = length text > 2 && 2 == (length . takeWhile (==True) $ zipWith (==) "//" text)
- delimiter :: String -> Char
- delimiter text
- | hasDelimiter text = text !! 2
- | otherwise = '\n'
- calc :: String -> Int
- calc text = sum . map readInt . numbers . body $ text
- where numbers = splitBy (delimiter text)
- body text = if hasDelimiter text then drop 3 text else text
Add Comment
Please, Sign In to add comment