Day11: Part 2 Works
This commit is contained in:
parent
63d41f5084
commit
aae7079140
19
day11.hs
19
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)
|
||||
|
|
Loading…
Reference in New Issue