This commit is contained in:
2023-12-22 13:06:56 +01:00
parent b48a12c5cc
commit ee37670cb3
5 changed files with 115 additions and 0 deletions

23
day22/Part2.hs Normal file
View File

@@ -0,0 +1,23 @@
module Part2 where
import Commons
import qualified Data.Map.Strict as M
import qualified Data.Set as S
import Data.Foldable (maximumBy)
import Data.Function (on)
getFutureFall' :: Snapshot -> S.Set Brick -> S.Set Brick
getFutureFall' s sFell =
let falling = getFalling s
in if null falling then sFell
else let fell = getFell s falling
newSFell = S.union (S.difference sFell (S.fromList $ map snd falling)) $ S.fromList $ map snd fell
in getFutureFall' (getPostFall s falling fell) newSFell
getFutureFall :: Snapshot -> Brick -> S.Set Brick
getFutureFall s b = let newSnapshot = M.difference s $ M.fromList $ map (\ c -> ((z c, y c, x c), b)) b
in getFutureFall' newSnapshot S.empty
getReactions :: Snapshot -> [S.Set Brick]
getReactions s = S.toList $ S.fromList $ map (getFutureFall s) $ M.elems s