fun fact! transpose exists

This commit is contained in:
Jill 2022-12-05 09:58:43 +03:00
parent a1776f40c9
commit 657087d6ed
2 changed files with 4 additions and 8 deletions

6
5-a.hs
View File

@ -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

6
5-b.hs
View File

@ -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