Copyright | (c) Eric Mertens 2021 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
https://adventofcode.com/2021/day/22
This problem is made simple by processing commands by subtracting away all future cuboids. Only the region unique to the current command will affect the final output.
Synopsis
- data C
- main :: IO ()
- solve :: [(C, Box n)] -> Int
- applyCommand :: [Box n] -> (C, Box n) -> [Box n]
- data Seg = Seg !Int !Int
- len :: Seg -> Int
- intersectSeg :: Seg -> Seg -> Maybe Seg
- inSeg :: Int -> Seg -> Bool
- data N
- data Box :: N -> Type where
- size :: Box n -> Int
- intersectBox :: Box n -> Box n -> Maybe (Box n)
- subBox :: Box n -> Box n -> [Box n]
- traverseBox2 :: Applicative f => (Seg -> Seg -> f Seg) -> Box n -> Box n -> f (Box n)
Documentation
Apply a command given a list of non-overlapping, illuminated regions.
Segments
A segment defined by an inclusive lower-bound and an exclusive upper-bound.
N-dimensional boxes
Returns the number of points contained in a box.
>>>
size (Seg 1 4 :* Seg 0 3 :* Seg 0 2 :* Pt)
18
intersectBox :: Box n -> Box n -> Maybe (Box n) Source #
The intersection of two boxes is the intersection of their segments.
Subtract the second box from the first box returning a list of boxes that cover all the remaining area.
>>>
subBox (Seg 2 3 :* Pt) (Seg 0 4 :* Pt)
[Seg 0 2 :* Pt,Seg 3 4 :* Pt]
>>>
subBox (Seg 3 5 :* Pt) (Seg 0 4 :* Pt)
[Seg 0 3 :* Pt]
traverseBox2 :: Applicative f => (Seg -> Seg -> f Seg) -> Box n -> Box n -> f (Box n) Source #
Zip two boxes together.