Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE OverloadedStrings #-}
- import Data.Char
- import qualified Data.Text as T
- first string
- | isDigit (T.head string) = digitToInt (T.head string)
- | "one" `T.isPrefixOf` string = 1
- | "two" `T.isPrefixOf` string = 2
- | "three" `T.isPrefixOf` string = 3
- | "four" `T.isPrefixOf` string = 4
- | "five" `T.isPrefixOf` string = 5
- | "six" `T.isPrefixOf` string = 6
- | "seven" `T.isPrefixOf` string = 7
- | "eight" `T.isPrefixOf` string = 8
- | "nine" `T.isPrefixOf` string = 9
- | otherwise = first (T.tail string)
- last1 string
- | isDigit (T.head string) = digitToInt (T.head string)
- | "eno" `T.isPrefixOf` string = 1
- | "owt" `T.isPrefixOf` string = 2
- | "eerht" `T.isPrefixOf` string = 3
- | "ruof" `T.isPrefixOf` string = 4
- | "evif" `T.isPrefixOf` string = 5
- | "xis" `T.isPrefixOf` string = 6
- | "neves" `T.isPrefixOf` string = 7
- | "thgie" `T.isPrefixOf` string = 8
- | "enin" `T.isPrefixOf` string = 9
- | otherwise = last1 (T.tail string)
- getResult string = 10 * (first (T.pack (string))) + last1 (T.reverse (T.pack string))
- main = do
- str <- getContents
- print (sum(map getResult (lines str)))
Advertisement
Advertisement