|
| 1 | +## Day 12: Garden Groups |
| 2 | + |
| 3 | +Visit the Advent of Code website for more information on this puzzle at: |
| 4 | + |
| 5 | +**Source:** https://adventofcode.com/2024/day/12<br> |
| 6 | +**Status:** Complete ⭐⭐ |
| 7 | + |
| 8 | +## Code |
| 9 | + |
| 10 | +### `garden.ts` |
| 11 | + |
| 12 | +- **Garden** class |
| 13 | + - A set of methods and properties for calculating Garden, Region, and Plots data |
| 14 | + - `Garden.calculatePlot()` - Calculates the per-plot perimeter and total area of all garden regions in a 2D grid, each defined by an initial symbol at a starting (y,x) coordinate. |
| 15 | + - `Garden.calculateFencePrice()` - Calculates the total fencing price of all regions in a garden per connected plot using the formula: area * perimeter (per plot). |
| 16 | + |
| 17 | +### `wholesale.ts` |
| 18 | + |
| 19 | +- **WholesaleGarden** class |
| 20 | + - A set of methods and properties for calculating the wholesale fencing price of garden regions |
| 21 | + - `WholesaleGarden.calculateRegionCorners()` - Calculates the number of corners (sides) of a whole region. |
| 22 | + - `WholesaleGarden.calculateFencePrice()` - Calculates the total fencing price of all regions in a garden using the formula: area * perimeter (of whole region). |
| 23 | + |
| 24 | +### `utils.ts` |
| 25 | + |
| 26 | +- A script containing helper and utility scripts for the quiz |
| 27 | +- `findNeighbors()` - Finds all coordinates of the neighboring plots from a specified coordinate (up/down/left/right) |
| 28 | +- `isIllegalCoordinate()` - Checks if a point at coordinate (y,x) in a grid is illegal: if it's out of bounds of the grid area or if its symbol differs from the symbol parameter. |
| 29 | +- `getDiagonalNeighbors()` - Retrieves the four (4) diagonally-aligned (y,x) coordinates and the symbol character from a `Point` in the grid. Substitutes a `"*"` symbol character in the `NeighborPoint.symbol`if the `point` is out of the grid bounds. |
| 30 | +- `getCrossNeighbors()` - Retrieves the four (4) horizontal/vertical aligned (y,x) coordinates and the symbol character from a `Point` in the grid. Substitutes a `"*"` symbol character in the `NeighborPoint.symbol`if the `point` is out of the grid bounds. |
| 31 | +- `isDiagonal()` - Checks if two (2) `Points` are diagonally-aligned |
| 32 | +- `innerCorners()` - Counts the "inner" corners from groups of valid L-shaped `Points` that originate from a `Point` coordinate. |
| 33 | + |
| 34 | + |
| 35 | +## Notes |
| 36 | + |
| 37 | +1. Garden Plot |
| 38 | + - only 1 plant |
| 39 | + - single letter |
| 40 | + - 4 sides |
| 41 | + |
| 42 | +2. Region |
| 43 | + - garden plots that are touching (vertically/horizontally) |
| 44 | + |
| 45 | +3. Region: Area |
| 46 | + - number of garden plots in the region |
| 47 | + |
| 48 | +4. Region: Perimeter |
| 49 | + - no. of sides of garden plots in the region that do not touch another garden plot |
| 50 | + |
| 51 | +5. Thoughts/tips across the subreddit/google: |
| 52 | + - no. of corners = no. of sides 😉 |
| 53 | + |
| 54 | +## References |
| 55 | + |
| 56 | +<sup>[[1]](https://en.wikipedia.org/wiki/Flood_fill)</sup> Flood Fill Algorithm |
0 commit comments