Abbreviations, automatic: Difference between revisions

Content deleted Content added
Hout (talk | contribs)
→‎{{header|Haskell}}: Simplified by using transpose . (inits <$>)
Hout (talk | contribs)
→‎{{header|Haskell}}: Generalised beyond the specific case of 7 strings
Line 282:
<lang haskell>import Data.List (inits, nub, transpose)
 
abbrevns :: [String] -> [[String]]
abbrevns xs =
let lng = length xs
take 1 . dropWhile ((< 7) . length) . (nub <$>) . transpose . (inits <$>)
in case lng of
0 -> []
_ ->
head $
(take 1 .
take 1 . dropWhile ((< 7lng) . length) . (nub <$>) . transpose . (inits <$>))
xs
 
abbreviations :: String -> [String]
abbreviations = (fmap (unwords . head . abbrevns) words <$>) . lines
 
main :: IO ()
main = do
s <- readFile "./weekDayNames.txt"
mapM_ putStrLn $ take 5 (abbreviations s)</lang>
</lang>
{{Out}}
<pre>Su Mo Tu We Th Fr Sa