Day15: Part 2 works
This commit is contained in:
parent
6e36014987
commit
ea5b4b48de
14
day15.hs
14
day15.hs
|
@ -11,8 +11,18 @@ main = do
|
||||||
let resultRobots = (runRobot robot )
|
let resultRobots = (runRobot robot )
|
||||||
let winRobots = filter(\(Robot br pts pos dir) -> elem 2 (map(\(p,c) -> c) pts))resultRobots
|
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 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(show winRobotsLength)
|
||||||
putStrLn ("ELL")
|
putStrLn(show $ List.maximum( part2Length))
|
||||||
|
|
||||||
data Amplifier = Amplifier{ state :: [Int]
|
data Amplifier = Amplifier{ state :: [Int]
|
||||||
,index :: Int
|
,index :: Int
|
||||||
|
@ -72,12 +82,10 @@ move (x,y) direction
|
||||||
|
|
||||||
getNextMove :: Robot -> [Int]
|
getNextMove :: Robot -> [Int]
|
||||||
getNextMove (Robot brain points position direction)
|
getNextMove (Robot brain points position direction)
|
||||||
|length points == 300 = []
|
|
||||||
|length points > 0 && (snd $ last points) == 2 = []
|
|length points > 0 && (snd $ last points) == 2 = []
|
||||||
|otherwise = do
|
|otherwise = do
|
||||||
filterMoves (Robot brain points position direction) [1,2,3,4]
|
filterMoves (Robot brain points position direction) [1,2,3,4]
|
||||||
|
|
||||||
|
|
||||||
filterMoves :: Robot -> [Int] -> [Int]
|
filterMoves :: Robot -> [Int] -> [Int]
|
||||||
filterMoves robot moves = filter(\x -> checkVisit robot x && checkWall robot x) moves
|
filterMoves robot moves = filter(\x -> checkVisit robot x && checkWall robot x) moves
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user