From f725b279539c791f0d4efdaf731ce564fc9153ba Mon Sep 17 00:00:00 2001 From: Arranun Date: Sat, 7 Dec 2019 22:27:53 +0100 Subject: [PATCH] day7: degug --- day7.hs | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/day7.hs b/day7.hs index 45ce054..ff68299 100644 --- a/day7.hs +++ b/day7.hs @@ -2,21 +2,20 @@ import Data.List.Split import Data.Char as Char import Data.List as List import Data.Either as Either +import Debug.Trace as Debug main = do software <- getList <$> getContents --let output = operation state state 0 input [] - let combs = getComb [5,6,7,8,9] - mapM putStrLn(map show combs) + let combs = [[9,8,7,6,5]] + --mapM putStrLn(map show combs) mapM putStrLn(map show ( map (\x-> part2 $ prepareAmps x software ) combs )) -- let output = calcthruster software [4,3,2,1,0] data Amplifier = Amplifier{ state :: [Int] ,index :: Int ,input :: [Int] - ,output :: [Int] } -type Outputtype = Either [Int] Amplifier - + ,output :: [Int] } deriving Show getList :: String -> [Int] getList = map read . splitOn "," @@ -42,12 +41,12 @@ part2 amps = do let ampE = link (ampD) (amps!!4) if state ampE == [88] then head (output (amps!!4)) - else part2 [ampA,ampB,ampC,ampD,ampE] + else part2 (Debug.traceShowId([ampA,ampB,ampC,ampD,ampE])) link :: Amplifier -> Amplifier -> Amplifier link left calc - | length (output left) == 0 = Amplifier ([88]) (index calc) (input calc) (output calc) - | otherwise = step calc [last $ output left] + | null (output left) = Amplifier ([88]) (index calc) (input calc) (output calc) + | otherwise = step calc (Debug.traceShowId([last $ output left])) step :: Amplifier -> [Int] -> Amplifier step amp input = operation (drop (index amp) (state amp)) (state amp) (index amp) input [] @@ -65,43 +64,43 @@ calcthrusters software (p1:p2:p3:p4:p5:_) start = do operation :: [Int] -> [Int] -> Int -> [Int] -> [Int] -> Amplifier operation (99:_) state i input output = - Amplifier state i input [] + Amplifier state i input output operation (op:x:y:z:_) state i input output | last (digits op) == 1 = do let newindex = i + 4 let newstate = add (fillup (revertdigs op) 5) x y z state - operation (drop newindex newstate) newstate newindex input output + operation (Debug.traceShowId(drop newindex newstate)) (Debug.traceShowId(newstate)) newindex input output | last (digits op) == 2 = do let newindex = i + 4 let newstate = mult (fillup (revertdigs op) 5) x y z state - operation (drop newindex newstate) newstate newindex input output + operation (Debug.traceShowId((drop newindex newstate))) (Debug.traceShowId(newstate)) newindex input output | last (digits op) == 3 = do - if length input == 0 - then Amplifier state i input output + if (Debug.traceShowId(length input)) == 0 + then (Debug.traceShowId(Amplifier state i input output)) else do let newindex = i + 2 let newstate = put (fillup (revertdigs op) 3) x (head input) state let newinput = drop 1 input - operation (drop newindex newstate) newstate newindex newinput output + operation (Debug.traceShowId((drop newindex newstate))) (Debug.traceShowId(newstate)) newindex newinput output | last (digits op) == 4 = do let newindex = i + 2 let newoutput = out (fillup (revertdigs op) 3) output x state let newinput = drop 1 input - operation (drop newindex state) state newindex input newoutput + operation (Debug.traceShowId((drop newindex state))) (Debug.traceShowId(state)) newindex input (newoutput) | (last (digits op) == 5 ) = do let newindex = jumpif (fillup (revertdigs op) 4) x y i state - operation (drop newindex state) state newindex input output + operation (Debug.traceShowId((drop newindex state))) (Debug.traceShowId(state)) newindex input output | (last (digits op) == 6 ) = do let newindex = jumpifnot (fillup (revertdigs op) 4) x y i state - operation (drop newindex state) state newindex input output + operation (Debug.traceShowId((drop newindex state))) (Debug.traceShowId(state)) newindex input output | (last (digits op) == 7 ) = do let newindex = i + 4 let newstate = lessthan (fillup (revertdigs op) 5) x y z state - operation (drop newindex newstate) newstate newindex input output + operation (Debug.traceShowId((drop newindex newstate))) (Debug.traceShowId(newstate)) newindex input output | (last (digits op) == 8 ) = do let newindex = i + 4 let newstate = equal (fillup (revertdigs op) 5) x y z state - operation (drop newindex newstate) newstate newindex input output + operation (Debug.traceShowId((drop newindex newstate))) (Debug.traceShowId(newstate)) newindex input output add :: [Int] -> Int -> Int -> Int -> [Int] -> [Int] add (op1:op2:m1:m2:m3:_) p1 p2 p3 state =