columnv2 => moins de lignes, utilisation de list comprehension

This commit is contained in:
karchnu 2016-01-08 04:29:12 +01:00
parent c20d0b6e0b
commit a92640a487

19
haskell/columnv2.hs Normal file
View File

@ -0,0 +1,19 @@
import Data.List as L
formatLine :: [String] -> [String]
formatLine x = map (\e -> e ++ [' ' | _ <- [length e..nb]]) x
where nb = maximum $ map length x
formatLines :: [[String]] -> [[String]]
formatLines x = map formatLine x
completeMatrix :: [[String]] -> [[String]]
completeMatrix m = map (\e -> e ++ [""| _ <- [length e..nb]]) m
where nb = maximum $ map length m
column :: [[String]] -> [[String]]
column x = L.transpose $ formatLines $ L.transpose $ completeMatrix x
main = do
content <- getContents
putStr $ unlines $ map unwords $ column $ map words $ lines content