fun fact! transpose exists
This commit is contained in:
parent
a1776f40c9
commit
657087d6ed
6
5-a.hs
6
5-a.hs
|
@ -3,12 +3,10 @@
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import GHC.Utils.Misc (chunkList)
|
import GHC.Utils.Misc (chunkList)
|
||||||
import Data.Char (isSpace, isNumber)
|
import Data.Char (isSpace, isNumber)
|
||||||
|
import Data.List (transpose)
|
||||||
rotate2DList :: [[a]] -> [[a]]
|
|
||||||
rotate2DList l = map (\i -> map (!! i) l) [0 .. length (head l) - 1]
|
|
||||||
|
|
||||||
parseState :: String -> [[Char]]
|
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 :: String -> [(Int, Int)]
|
||||||
parseInstructions = concatMap ((\[n, a, b] -> replicate n (a, b)) . map read . filter (isNumber . head) . words) . lines
|
parseInstructions = concatMap ((\[n, a, b] -> replicate n (a, b)) . map read . filter (isNumber . head) . words) . lines
|
||||||
|
|
6
5-b.hs
6
5-b.hs
|
@ -3,12 +3,10 @@
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import GHC.Utils.Misc (chunkList)
|
import GHC.Utils.Misc (chunkList)
|
||||||
import Data.Char (isSpace, isNumber)
|
import Data.Char (isSpace, isNumber)
|
||||||
|
import Data.List (transpose)
|
||||||
rotate2DList :: [[a]] -> [[a]]
|
|
||||||
rotate2DList l = map (\i -> map (!! i) l) [0 .. length (head l) - 1]
|
|
||||||
|
|
||||||
parseState :: String -> [[Char]]
|
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 :: String -> [(Int, Int, Int)]
|
||||||
parseInstructions = map ((\[n, a, b] -> (n, a, b)) . map read . filter (isNumber . head) . words) . lines
|
parseInstructions = map ((\[n, a, b] -> (n, a, b)) . map read . filter (isNumber . head) . words) . lines
|
||||||
|
|
Loading…
Reference in New Issue