

Haskell
Very simple, this one.
import Data.List
import Data.Set qualified as Set
readInput s =
Set.fromDistinctAscList
[ (i, j) :: (Int, Int)
| (i, l) <- zip [0 ..] (lines s),
(j, c) <- zip [0 ..] l,
c == '@'
]
accessible ps = Set.filter ((< 4) . adjacent) ps
where
adjacent (i, j) =
length . filter (`Set.member` ps) $
[ (i + di, j + dj)
| di <- [-1 .. 1],
dj <- [-1 .. 1],
(di, dj) /= (0, 0)
]
main = do
input <- readInput <$> readFile "input04"
let removed =
(`unfoldr` input) $
\ps ->
case accessible ps of
d
| Set.null d -> Nothing
| otherwise -> Just (Set.size d, ps Set.\\ d)
print $ head removed
print $ sum removed





Haskell
IntSetwas the wrong first choice for part 2 :3