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) | Just i <- findIndex (`isPrefixOf` l) digits = f (Just $ i+1) <> parse xs | otherwise = 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