X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=advent22%2FMain.hs;h=55b64b636a83f0d86512e03ec074e40bf46887e8;hb=ac1cb7b87194225d518bae8e5a9d9efe7d27220a;hp=87bdf6cb0b834c2cbd0d6cb577e28c41a49e1d1b;hpb=5e886d892c0bef76b3f0fbac7de1001e75dabebb;p=advent-of-code-23.git diff --git a/advent22/Main.hs b/advent22/Main.hs index 87bdf6c..55b64b6 100644 --- a/advent22/Main.hs +++ b/advent22/Main.hs @@ -12,8 +12,8 @@ import Linear -- import Linear.V3 import Data.List import Data.Function -import qualified Data.Map as M -import Data.Map ((!)) +import qualified Data.Map.Strict as M +import Data.Map.Strict ((!)) import qualified Data.Set as S type Block = (V3 Int, V3 Int) @@ -63,9 +63,11 @@ dropBlocks blocks = foldl' dropBlock [] blocks dropBlock :: [Block] -> Block -> [Block] dropBlock resting block = resting ++ [over both (^-^ (V3 0 0 fallDistance)) block] - where _2xy = alongside _xy _xy - blockPlane = block ^. _2xy - under = filter ((intersectsXY blockPlane) . (view _2xy)) resting + where -- _2xy = alongside _xy _xy + -- blockPlane = block ^. _2xy + blockPlane = over both (view _xy) block + -- under = filter ((intersectsXY blockPlane) . (view _2xy)) resting + under = filter ((intersectsXY blockPlane) . (over both (view _xy))) resting highestUnder = maxZ under fallDistance = block ^. _1 . _z - highestUnder - 1 @@ -124,7 +126,7 @@ blockP :: Parser Block vertexP :: Parser (V3 Int) blocksP = blockP `sepBy` endOfLine -blockP = cubify <$> (vertexP <* "~") <*> vertexP +blockP = cubify <$> vertexP <* "~" <*> vertexP where cubify (V3 x1 y1 z1) (V3 x2 y2 z2) = ( (V3 (min x1 x2) (min y1 y2) (min z1 z2)) , (V3 (max x1 x2) (max y1 y2) (max z1 z2))