With catMaybes
[advent-of-code-22.git] / advent05 / Main.hs
index 9ec1d254707abaf10b2e7818813c7681050a8dbe..21daf434eb0f17035f9b4542a926e88e56235291 100644 (file)
@@ -22,12 +22,7 @@ main =
   do  dataFileName <- getDataFileName
       text <- TIO.readFile dataFileName
       let ((wharfLines, colNames), moves) = successfulParse text
-      -- print wharfLines
-      -- print colNames
-      -- print moves
       let wharf = makeWharf wharfLines colNames
-      -- print wharf
-      -- print $ applyMove wharf (head moves)
       putStrLn $ part1 wharf moves
       putStrLn $ part2 wharf moves
 
@@ -57,9 +52,7 @@ extractName (Crate c) = c
 
 makeWharf :: [[Maybe Crate]] -> [Int] -> Wharf
 makeWharf wharfLines colNames = M.fromList $ zip colNames wharfCols
-  where wharfCols = fmap (fmap fromJust)
-                  $ fmap (dropWhile isNothing) 
-                  $ transpose wharfLines
+  where wharfCols = fmap catMaybes $ transpose wharfLines
 
 applyMoves1 :: Wharf -> [Move] -> Wharf
 applyMoves1 wharf moves = foldl' applyMove1 wharf moves