Safe Haskell | None |
---|
Day17
Description
General - There is good news and bad news. The good news is that the first half of the problem is easy to solve: We just maintain a set of active coordinates and check/filter in every cycle, if the coordinates remain active.
The second half is harder to solve/check, because the number of inactive coordinates is indefinite. We need to find a way to limit the search space.
One way to do this wouldcould be to look for the minmax of xyz, add 1 in every direction, create all possible coordinates, remove the ones that are active and then check the remaining ones.
That can be(come) a big problem fast.
Another way to do it would be to start with the active coordinates and declare all coordinates around them inactive, remove the active ones and check the remaining ones.
That sounds more managable. Let's go with that.
Part 1 - Just cycle 6 times.
Part 2 - Ok ... I am cheating here. My implementation is not dimension-independent, means ... I am *just* duplicating the code (datastructures and algorithms) to make it work with/in 4 dimension. Not pretty, but ... it works.
Synopsis
- type Coordinate = (Int, Int, Int)
- type Coordinate' = (Int, Int, Int, Int)
- type Pocket = Set Coordinate
- type Pocket' = Set Coordinate'
- input :: String -> Pocket
- input' :: String -> Pocket'
- neighborOffsets :: [Coordinate]
- neighborOffsets' :: [Coordinate']
- runCycle :: Pocket -> Pocket
- runCycle' :: Pocket' -> Pocket'
- part1 :: Pocket -> Int
- part2 :: Pocket' -> Int
Documentation
type Coordinate = (Int, Int, Int) #
type Coordinate' = (Int, Int, Int, Int) #
type Pocket = Set Coordinate #
type Pocket' = Set Coordinate' #
neighborOffsets :: [Coordinate] #
Get the offsets for the neighbors (for part1).
neighborOffsets' :: [Coordinate'] #
Get the offsets for the neighbors (for part2).