Safe Haskell | None |
---|
Day24
Description
General - To solve this you have to think about (or google) how to navigatewalk a hex-grid (https:trits.ch3bJeNeZ).
To solve this we walk all the steps for any given tile and will end up with a/the list of destination tiles.
Part 1 - Look for all destination tiles that are there/where flipped an odd number of times.
Part 2 - Take the result from part1 and start applying the rules day after day. To implement the rules we need to understand how many black tiles are adjacent to a given (black or white) tile (e.g. (count, position)). We can then apply the rules and flip the tiles accordingly.
Note: The grid has no boundaries. Means the number of white tiles is indefinte. But the number/list of black tiles is not. Means we will model the grid by means of a list of black tiles (all other tiles are (by definition) white).
Synopsis
- type Step = String
- type Steps = [Step]
- type Tiles = [Steps]
- data Position = Position Int Int
- input :: String -> Tiles
- walk :: Steps -> Position -> Position
- initialBlackTiles :: Tiles -> [Position]
- part1 :: Tiles -> Int
- numberOfAdjacentBlackTiles :: Position -> [Position] -> Int
- numberOfAdjacentBlackTiles' :: [Position] -> [Position] -> [(Int, Position)]
- checkRule :: ((Int, Position) -> Bool) -> [(Int, Position)] -> [Position]
- blackRule :: (Int, Position) -> Bool
- whiteRule :: (Int, Position) -> Bool
- allAdjacent :: Position -> [Position]
- isAdjacent :: Position -> Position -> Bool
- allWhiteTiles :: [Position] -> [Position]
- doDay :: [Position] -> [Position]
- part2 :: Tiles -> Int
Documentation
walk :: Steps -> Position -> Position #
Walk a step (until there are no more steps) and (at the end) return the final position.
initialBlackTiles :: Tiles -> [Position] #
Take a list of tile paths, flip them over and return a/the list of black tiles/positions.
numberOfAdjacentBlackTiles :: Position -> [Position] -> Int #
For a given tile, return the number of adjacent black tiles
numberOfAdjacentBlackTiles' :: [Position] -> [Position] -> [(Int, Position)] #
For a list of tiles, return the number of adjacent black tiles
checkRule :: ((Int, Position) -> Bool) -> [(Int, Position)] -> [Position] #
Check the rule and return the qualified tiles.
blackRule :: (Int, Position) -> Bool #
Any black tile with zero or more than 2 black tiles immediately adjacent to it needs to be flipped (to white).
whiteRule :: (Int, Position) -> Bool #
Any white tile with exactly 2 black tiles immediately adjacent to it needs to be flipped (to black).
allAdjacent :: Position -> [Position] #
Return all adjacent tiles for the given tile.
isAdjacent :: Position -> Position -> Bool #
Tests, if a two tiles are adjacent.
allWhiteTiles :: [Position] -> [Position] #
For the given list of black tiles, return a/the list of white that need to be checked/considered.