Longest common prefix: Difference between revisions
Content added Content deleted
m (People can disagree on what "well designed" means in technical contexts, so spell out what was meant) |
m (→{{header|Haskell}}: (swapped one <$> to an fmap, relieving the need for brackets)) |
||
Line 774:
:: (Eq a)
=> [[a]] -> [a]
lcp =
where
-- Similar to transpose, but stops on end of shortest list.▼
truncTranspose :: [[a]] -> [[a]]
truncTranspose xs
Line 786 ⟶ 785:
allEqual (x:xs) = all (== x) xs
showPrefix :: [String] -> String
showPrefix xs = show xs ++ " -> " ++ show (lcp xs)
Line 804:
])
putStrLn []
print $ lcp ["abc" ++ repeat 'd', "abcde" ++ repeat 'f'] -- prints
{{Out}}
<pre>["interspecies","interstellar","interstate"] -> "inters"
|