diff --git a/5-a.hs b/5-a.hs index 0aa6bc6..2af126d 100644 --- a/5-a.hs +++ b/5-a.hs @@ -3,12 +3,10 @@ import qualified Data.Text as T import GHC.Utils.Misc (chunkList) import Data.Char (isSpace, isNumber) - -rotate2DList :: [[a]] -> [[a]] -rotate2DList l = map (\i -> map (!! i) l) [0 .. length (head l) - 1] +import Data.List (transpose) parseState :: String -> [[Char]] -parseState = map (dropWhile isSpace) . rotate2DList . map (map (!! 1) . chunkList 4) . init . lines +parseState = map (dropWhile isSpace) . transpose . map (map (!! 1) . chunkList 4) . init . lines parseInstructions :: String -> [(Int, Int)] parseInstructions = concatMap ((\[n, a, b] -> replicate n (a, b)) . map read . filter (isNumber . head) . words) . lines diff --git a/5-b.hs b/5-b.hs index b5e73f4..c307433 100644 --- a/5-b.hs +++ b/5-b.hs @@ -3,12 +3,10 @@ import qualified Data.Text as T import GHC.Utils.Misc (chunkList) import Data.Char (isSpace, isNumber) - -rotate2DList :: [[a]] -> [[a]] -rotate2DList l = map (\i -> map (!! i) l) [0 .. length (head l) - 1] +import Data.List (transpose) parseState :: String -> [[Char]] -parseState = map (dropWhile isSpace) . rotate2DList . map (map (!! 1) . chunkList 4) . init . lines +parseState = map (dropWhile isSpace) . transpose . map (map (!! 1) . chunkList 4) . init . lines parseInstructions :: String -> [(Int, Int, Int)] parseInstructions = map ((\[n, a, b] -> (n, a, b)) . map read . filter (isNumber . head) . words) . lines