From aae707914003a8ef7a301c92f53dee82c80d327b Mon Sep 17 00:00:00 2001 From: Arranun Date: Wed, 11 Dec 2019 19:48:42 +0100 Subject: [PATCH] Day11: Part 2 Works --- day11.hs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/day11.hs b/day11.hs index 1610f1b..05177b5 100644 --- a/day11.hs +++ b/day11.hs @@ -7,18 +7,13 @@ import Debug.Trace as Trace main = do software <- getList <$> getContents let brain = Amplifier software 0 0 [] [0] - let robot = Robot brain [] (0,0) 0 + let robot = Robot brain [((0,0),1)] (0,0) 0 let result = runRobot robot let endPoints = points result let pointsNoColor = map(\(x,y) -> x) endPoints let unique = nub pointsNoColor - let newEndPoints = map(\((a,b),c) -> ((a+25,b),c)) endPoints - let mapPoint = createMap newEndPoints [-50..50] [] - --putStrLn(show $ length $ points result) - putStrLn(show $ newEndPoints) + let mapPoint = createMap endPoints (reverse [-7..1]) [] mapM putStrLn( map show mapPoint) - --putStrLn(show (index (getBrain result))) - putStrLn ("HELLO") data Amplifier = Amplifier{ state :: [Int] ,index :: Int @@ -37,12 +32,12 @@ getBrain :: Robot -> Amplifier getBrain (Robot brain points poisition direction) = brain createMap ::[((Int,Int),Int)]-> [Int] -> [[Int]] -> [[Int]] -createMap points (x:xs) output - |length xs > 0 = do - let fPoints = filter(\((a,b),c) -> b == x) points +createMap points (y:ys) output + |length ys > 0 = do + let fPoints = filter(\((a,b),c) -> b ==y ) points let row = foldl createRow [] fPoints let newoutput = output ++ [(Trace.traceShowId(row))] - createMap points xs newoutput + createMap points ys newoutput |otherwise = output createRow :: [Int] -> ((Int,Int),Int) -> [Int] @@ -60,7 +55,7 @@ runRobot (Robot brain points position direction) = do else do let outColor = (output (newBrain))!!0 let outMove = (output newBrain)!!1 - let newPoints = ( (points \\ currentpoint) ++ [(position,outColor)]) + let newPoints = ( (points \\ currentpoint) ++ [(position,outColor)]) let newDirection = changeDirection direction outMove let newPos = move position newDirection runRobot (Robot newBrain newPoints newPos newDirection)