Safe HaskellNone

Day11

Description

General - Seat System. Main problem to solve is to be able to to check the rules for a given seat. What is the best data structure for that? Options are ...

  • 2-dim array of seat status
  • map of coordinates to status
  • list of x,y,status triplets

Operations we need on this data structure are ...

  • lookup status
  • change status (not really, because we always build a new map)

We always need two maps, because we need athe old (unchanged unmodified) map to build the new map (because the status changes everywhere at the same time).

It would be cool, if (while we build the new/next map) we could also determine the neighbor count right away, but ... that is not possible (because the descison if a seat is occupied is made using the old/previous map).

But ... we can first build the new map and then build a helper map, where every cell has a/the neighbor count in it.

We can then start to do a recursion until the next map is the same as the previous map.

Part 1 - That's what we did for part 1.

Part 2 - Was much more difficult, because we do not need the adjacent neighbor count, but the count of occupied and empty seats we can see/ reach (walking from the current position; over the floor; in all 8 directions).

Synopsis

Documentation

type Location = (Int, Int) #

type Dimensions = (Int, Int) #

type Status = Char #

type Distance = (Int, Status) #

data Seats #

The current seats status.

input :: String -> Seats #

Read the input file.

makeNeighbors :: SeatsStatus -> Dimensions -> SeatsNeighborDistanceMap #

Take the current status and return a/the distance map for it.

seatingArea :: (Seats -> Location -> Status) -> Seats -> [Char] #

(Recursively) Iterate over the seating area.

calcStatus' :: Seats -> Location -> Status #

The transition function for part1.

solve :: (Seats -> Location -> Status) -> Seats -> Int #

Solve the puzzle with the given status transition function.

part1 :: Seats -> Int #

Solve part1.

calcStatus'' :: Seats -> Location -> Status #

The transition function for part2.

part2 :: Seats -> Int #

Solve part2.