24 lines
857 B
Haskell
24 lines
857 B
Haskell
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
|