Tidying
[advent-of-code-16.git] / advent21.hs
index fdb13814d3d6c07c0a098fd5ef0a975ad1a2696b..d51bd1076273b81be19b30fd0980a4511d47ffe8 100644 (file)
@@ -1,6 +1,5 @@
 import Text.Parsec hiding (State)
 import Text.ParserCombinators.Parsec.Number
--- import Control.Applicative ((<*), (*>), (<*>))
 import Data.Maybe (fromJust)
 import Data.List (elemIndex)
 
@@ -58,15 +57,19 @@ main = do
 
 part1 :: [Instruction] -> String -> IO ()
 part1 instructions start = 
-    let state = Password {password = start}
-    in print $ runIdentity (runStateT (runWriterT (apply instructions)) state)
-    -- in putStrLn $ password $ runIdentity (execStateT (runWriterT (apply instructions)) state)
+    let st = Password {password = start}
+        ((_, log), st') = runIdentity (runStateT (runWriterT (apply instructions)) st)
+    in do 
+        -- putStrLn $ unlines $ map (action) log
+        putStrLn $ password st'
 
 part2 :: [Instruction] -> String -> IO ()
 part2 instructions end = 
-    let state = Password {password = end}
-    in print $ runIdentity (runStateT (runWriterT (unApply instructions)) state)
-    -- in putStrLn $ password $ runIdentity (execStateT (runWriterT (apply instructions)) state)
+    let st = Password {password = end}
+        ((_, log), st') = runIdentity (runStateT (runWriterT (unApply instructions)) st)
+    in do 
+        -- putStrLn $ unlines $ map (action) log
+        putStrLn $ password st'
 
 
 apply :: [Instruction] -> App ()