Safe HaskellNone

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

Documentation

type Step = String #

type Steps = [Step] #

type Tiles = [Steps] #

data Position #

Constructors

Position Int Int 

Instances

Instances details
Eq Position # 
Instance details

Defined in Day24

Methods

(==) :: Position -> Position -> Bool

(/=) :: Position -> Position -> Bool

Ord Position # 
Instance details

Defined in Day24

Methods

compare :: Position -> Position -> Ordering

(<) :: Position -> Position -> Bool

(<=) :: Position -> Position -> Bool

(>) :: Position -> Position -> Bool

(>=) :: Position -> Position -> Bool

max :: Position -> Position -> Position

min :: Position -> Position -> Position

Show Position # 
Instance details

Defined in Day24

Methods

showsPrec :: Int -> Position -> ShowS

show :: Position -> String

showList :: [Position] -> ShowS

input :: String -> Tiles #

Read the input file and return the paths to the tiles to turn.

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.

part1 :: Tiles -> Int #

Solve part1.

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.

doDay :: [Position] -> [Position] #

Do a day of work.

part2 :: Tiles -> Int #

Solve part2.