fork download
  1. import System.Environment
  2.  
  3. slideWords :: Int -> String -> String -> (String, String)
  4. slideWords n a b = (drop ((length a) - n) a, take n b)
  5.  
  6. overlaps :: String -> String -> [(String, String)]
  7. overlaps a b = [slideWords n a b | n <- [0..minLength]]
  8. where minLength = min (length a) (length b)
  9.  
  10. longestOverlap :: String -> String -> String
  11. longestOverlap a b = fst $ last $ (filter (\(a,b) -> a==b) $ overlaps a b)
  12.  
  13. condenseWords :: String -> String -> String
  14. condenseWords a b = if overlap == ""
  15. then a ++ " " ++ b
  16. else a ++ (drop (length overlap) b)
  17. where overlap = longestOverlap a b
  18.  
  19. condense :: String -> String
  20. condense ws = foldr condenseWords "" $ words ws
  21.  
  22. main = do
  23. input <- fmap unwords getArgs
  24. putStrLn $ condense input
  25.  
Success #stdin #stdout 0s 8388607KB
stdin
I heard the pastor sing liverses easily.
Deep episodes of Deep Space Nine came on the television only after the news.
Digital alarm clocks scare area children.
stdout