Advertisement
banovski

Abjader

Sep 18th, 2024 (edited)
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haskell 1.08 KB | Source Code | 0 0
  1. -- The app reads text from stdin, picks words that are four or more characters
  2. -- long and removes non-initial vowels from them thus making words shorter but
  3. -- still in may cases comprehensible. All characters apart from letters and
  4. -- spaces are removed, spaces are replaced with underscores, uppercase letters
  5. -- are made lowercase. This sentence, processed by the app, looks like this:
  6. -- ths_sntnc_prcssd_by_the_app_lks_lk_ths
  7.  
  8. import System.Exit (die)
  9. import Data.Char (toLower)
  10. import Data.List (intercalate)
  11.  
  12. main :: IO ()
  13. main = do
  14.   input <- getContents
  15.   if null input
  16.     then die "No input!"
  17.     else putStr $
  18.          intercalate "_" $
  19.          map removeVowelsInLongWords $
  20.          words $ removeInvalidChars $ map toLower input
  21.  
  22. removeInvalidChars :: String -> String
  23. removeInvalidChars = filter (`elem` ['a' .. 'z'] ++ " ")
  24.  
  25. removeVowelsInLongWords :: String -> String
  26. removeVowelsInLongWords word
  27.   | length word < 4 = word
  28.   | otherwise = revomeVowels word
  29.   where
  30.     revomeVowels [] = []
  31.     revomeVowels (x:xs) = x : filter (not . (`elem` "aeiouy")) xs
  32.  
Tags: words text Vowels
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement