diff --git a/day15.hs b/day15.hs index eb1f0fb..333eec3 100644 --- a/day15.hs +++ b/day15.hs @@ -11,8 +11,18 @@ main = do let resultRobots = (runRobot robot ) let winRobots = filter(\(Robot br pts pos dir) -> elem 2 (map(\(p,c) -> c) pts))resultRobots let winRobotsLength = map(\(Robot br pts pos dir) -> length (filter(\(p,c) -> c == 1)pts))winRobots + let winRobot = (map(\(Robot br pts pos dir) -> Robot br [] pos 1) winRobots) !! 0 + let part2Robots = (runRobot winRobot) + let part2Length = map(\(Robot br pts pos dir) -> length (filter(\(p,c) -> c == 1)pts))part2Robots + let endPoints = foldl (++) [] (map(\(Robot br pts pos dir) -> pts) resultRobots) + let yMin = List.minimum (map(\((x,y),c) -> y) endPoints) + let yMax = List.maximum (map(\((x,y),c) -> y) endPoints) + let posEndPoints = map(\((a,b),c)-> ((a+30,b),c)) endPoints + let ship = createMap posEndPoints (reverse [yMin-1..yMax]) [] + mapM putStrLn(map show ship) + putStrLn(show $ length endPoints) putStrLn(show winRobotsLength) - putStrLn ("ELL") + putStrLn(show $ List.maximum( part2Length)) data Amplifier = Amplifier{ state :: [Int] ,index :: Int @@ -72,12 +82,10 @@ move (x,y) direction getNextMove :: Robot -> [Int] getNextMove (Robot brain points position direction) - |length points == 300 = [] |length points > 0 && (snd $ last points) == 2 = [] |otherwise = do filterMoves (Robot brain points position direction) [1,2,3,4] - filterMoves :: Robot -> [Int] -> [Int] filterMoves robot moves = filter(\x -> checkVisit robot x && checkWall robot x) moves