Abbreviations, automatic: Difference between revisions
Content deleted Content added
longest common prefix is a related and almost identical task |
→{{header|Haskell}}: A rough draft for base cases in Haskell |
||
Line 143: | Line 143: | ||
:* [[Longest common prefix]] |
:* [[Longest common prefix]] |
||
<br><br> |
<br><br> |
||
=={{header|Haskell}}== |
|||
<lang haskell>import Data.List (nub) |
|||
withAbbrevnLengths :: String -> [String] |
|||
withAbbrevnLengths s = |
|||
let ls = lines s |
|||
ws = words <$> ls |
|||
ns = minimum . fmap length <$> ws |
|||
ps = abbrevLen <$> zipWith (fmap . take) ns ws |
|||
in zipWith (\n t -> show n ++ '\t' : t) ps ls |
|||
abbrevLen |
|||
:: Eq a |
|||
=> [[a]] -> Int |
|||
abbrevLen xs = |
|||
let lng = length xs |
|||
in until -- the prefix length is either lng, or yields a nub of length lng |
|||
(((||) <$> (lng ==)) <*> \i -> lng == length (nub (take i <$> xs))) |
|||
succ |
|||
1 -- Initial prefix length taken |
|||
main :: IO () |
|||
main = do |
|||
s <- readFile "./weekDayNames.txt" |
|||
mapM_ putStrLn $ take 5 (withAbbrevnLengths s)</lang> |
|||
{{Out}} |
|||
<pre>2 Sunday Monday Tuesday Wednesday Thursday Friday Saturday |
|||
2 Sondag Maandag Dinsdag Woensdag Donderdag Vrydag Saterdag |
|||
4 E_djelë E_hënë E_martë E_mërkurë E_enjte E_premte E_shtunë |
|||
2 Ehud Segno Maksegno Erob Hamus Arbe Kedame |
|||
5 Al_Ahad Al_Ithinin Al_Tholatha'a Al_Arbia'a Al_Kamis Al_Gomia'a Al_Sabit</pre> |
|||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |