Day 11: Improve bounds

Some day lenses, maybe, when I read up on them
This commit is contained in:
shu 2019-12-12 22:55:44 +01:00
parent c94ec57f9f
commit b8e7d09015

View File

@ -6,6 +6,7 @@ import qualified Data.Map.Strict as M
import qualified Data.Vector as V import qualified Data.Vector as V
import Intcode import Intcode
import Linear.V2 import Linear.V2
import Control.Lens
data RoboState = data RoboState =
RoboState RoboState
@ -31,7 +32,7 @@ main = do
} }
, RoboState {hull = M.empty, position = V2 0 0, direction = V2 0 1}) , RoboState {hull = M.empty, position = V2 0 0, direction = V2 0 1})
print $ length $ hull $ snd $ run 0 print $ length $ hull $ snd $ run 0
putStrLn $ drawHull $ hull $ snd $ run 1 putStrLn $ drawHull $ M.filter (==1) $ hull $ snd $ run 1
drawHull :: M.Map (V2 Int) Integer -> String drawHull :: M.Map (V2 Int) Integer -> String
drawHull m = drawHull m =
@ -39,12 +40,12 @@ drawHull m =
transpose $ transpose $
map reverse $ map reverse $
chunksOf chunksOf
60 10
[ case M.findWithDefault 0 (V2 x y) m of [ case M.findWithDefault 0 (V2 x y) m of
1 -> '•' 1 -> '•'
_ -> ' ' _ -> ' '
| x <- [(-10) .. 49] | x <- [(-5) .. 44]
, y <- [(-10) .. 49] , y <- [(-5) .. 4]
] ]
runIntcode :: (TuringMachine, RoboState) -> (TuringMachine, RoboState) runIntcode :: (TuringMachine, RoboState) -> (TuringMachine, RoboState)