RosettaCodeData/Task/Odd-word-problem/Haskell/odd-word-problem-1.hs
2023-07-01 13:44:08 -04:00

21 lines
528 B
Haskell

import System.IO
(BufferMode(..), getContents, hSetBuffering, stdin, stdout)
import Data.Char (isAlpha)
split :: String -> (String, String)
split = span isAlpha
parse :: String -> String
parse [] = []
parse l =
let (a, w) = split l
(b, x) = splitAt 1 w
(c, y) = split x
(d, z) = splitAt 1 y
in a <> b <> reverse c <> d <> parse z
main :: IO ()
main =
hSetBuffering stdin NoBuffering >> hSetBuffering stdout NoBuffering >> getContents >>=
putStr . takeWhile (/= '.') . parse >>
putStrLn "."