Browse Source

Day13: Fix parseoutput

master
Arranun 2 years ago
parent
commit
e5adad16ed
  1. 10
      day13.hs

10
day13.hs

@ -13,7 +13,7 @@ main = do
let blocks =length $ M.filter(==2) step1Result
let result = runGame arcade M.empty
--let gameMap = createMap result [0..23] []
--let score = M.filterWithKey(\(V2 a b) _ -> a == -1 ) result
let score = M.filterWithKey(\(V2 a b) _ -> a == -1 ) result
--mapM putStrLn( map (map getSymbol) gameMap)
--putStrLn(show score)
putStrLn(show result)
@ -26,19 +26,19 @@ data Amplifier = Amplifier{ state :: [Int]
,output :: [Int]
} deriving Show
runGame :: Amplifier -> M.Map (V2 Int) Int -> [Int]
runGame :: Amplifier -> M.Map (V2 Int) Int -> M.Map (V2 Int) Int
runGame arcade gameM= do
let newArcade = step arcade [0]
let tiles = ((parseOutput M.empty (output newArcade)))
let newGameM = M.union tiles gameM
let blocks = length $ M.filter(== 2) newGameM
if blocks == 0
then output newArcade
if blocks == 0
then tiles
else runGame newArcade newGameM
parseOutput :: M.Map (V2 Int) Int -> [Int] -> M.Map (V2 Int) Int
parseOutput tiles (x:y:c:xs)
| length xs == 0 = tiles
| length xs == 0 = M.insert (V2 x y) c tiles
| length xs > 0 = parseOutput newtiles xs
where newtiles = M.insert (V2 x y) c tiles

Loading…
Cancel
Save