From 7748cd19bf3d3578af08933972226d7e271b26f7 Mon Sep 17 00:00:00 2001 From: karchnu Date: Mon, 4 Jan 2016 13:41:30 +0100 Subject: [PATCH] simplification column.hs, le code est beau <3 --- haskell/column.hs | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/haskell/column.hs b/haskell/column.hs index 69f3b03..ebf9648 100644 --- a/haskell/column.hs +++ b/haskell/column.hs @@ -1,16 +1,11 @@ -import qualified Data.Text as T - -splitOn :: String -> String -> [String] -splitOn x y = map T.unpack $ T.splitOn (T.pack x) $ T.pack y - transpose:: [[a]] -> [[a]] transpose ([]:xs) = [] transpose x = (map head x) : transpose (map tail x) addEmpty :: Int -> [a] -> [a] -> [a] addEmpty x v y - | ysize == x+1 = y - | ysize <= x = addEmpty x v (y ++ v) + | ysize == x = y + | ysize < x = addEmpty x v (y ++ v) | otherwise = [] where ysize = length y @@ -28,11 +23,6 @@ completeMatrix m = map (addEmpty nb [""]) m column :: [[String]] -> [[String]] column x = transpose $ formatLines $ transpose $ completeMatrix x -putToLines :: [[String]] -> [String] -putToLines x = map (foldr (++) " ") x - main = do content <- getContents - -- print $ column $ map (splitOn " ") $ lines content - -- print $ putToLines $ column $ map (splitOn " ") $ lines content - putStr $ unlines . putToLines $ column $ map (splitOn " ") $ lines content + putStr $ unlines $ map unwords $ column $ map words $ lines content