aoc::year2024

Module day12

Source
Expand description

§Garden Groups

Solves both parts simultaneously by flood filling each region.

For part one we increment the perimeter for each neighbouring plot belonging to a different region or out of bounds.

For part two we count each plot on the edge as either 0, 1 or 2 sides then divide by 2. An edge plot contributes nothing if it has 2 edge neighbours facing the same way, one if has a single neighbour and two if it has no neighbours.

For example, considering the right edge:

    ...        ...        .#. > 1
    .#. > 2    .#. > 1    .#. > 0
    ...        .#. > 1    .#. > 1

Functions§

Type Aliases§