import Prelude import Text.Read import Data.Maybe import Data.List import Data.Monoid import System.Environment digits = ["one","two","three","four","five","six","seven","eight","nine"] parse [] = (mempty,mempty) parse l@(x:xs) = case findIndex (`isPrefixOf` l) digits of Just i -> f (Just $ i+1) <> parse xs Nothing -> f (readMaybe [x]) <> parse xs where f = (,) . First <*> Last add (First x, Last y) = (+) . (*10) <$> x <*> y main = head <$> getArgs >>= readFile >>= print . sum . catMaybes . map (add . parse) <$> lines