X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=advent05%2FMain.hs;h=0b60f36fa0383dd000f6cadb345dba9a2976d915;hb=0aa43bda9bede3f58f97bc6b2996abd5dbbc97be;hp=9ec1d254707abaf10b2e7818813c7681050a8dbe;hpb=81f9c61ac7fe5482ba3210eede266450c4e562b6;p=advent-of-code-22.git

diff --git a/advent05/Main.hs b/advent05/Main.hs
index 9ec1d25..0b60f36 100644
--- a/advent05/Main.hs
+++ b/advent05/Main.hs
@@ -1,6 +1,6 @@
 -- Writeup at https://work.njae.me.uk/2022/12/04/advent-of-code-2022-day-4/
 
-import System.Environment
+import AoC
 import Data.Text (Text)
 import qualified Data.Text.IO as TIO
 import Data.Attoparsec.Text hiding (take)
@@ -22,27 +22,10 @@ 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
 
-
-getDataFileName :: IO String
-getDataFileName =
-  do args <- getArgs
-     progName <- getProgName
-     let baseDataName =  if null args
-                         then progName
-                         else head args 
-     let dataFileName = "data/" ++ baseDataName ++ ".txt"
-     return dataFileName
-
-
 part1 :: Wharf -> [Move] -> String
 part1 wharf moves = showTops $ applyMoves1 wharf moves
 
@@ -57,9 +40,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