Skip to content

Commit 4ac7ab8

Browse files
authored
Merge pull request #45 from weaponsforge/feat/weaponsforge-17
feat: day 12 garden groups 20241212
2 parents ac0b459 + aff86ab commit 4ac7ab8

File tree

23 files changed

+654
-16
lines changed

23 files changed

+654
-16
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ jobs:
2626
run: npm run lint
2727

2828
- name: Transpile
29-
run: npm run transpile
29+
run: npm run transpile:noemit
3030

3131
- name: Test
3232
run: npm test
33-

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
## ✨ adventofcode
22

3-
This repository contains solutions and a local development environment for the [Advent of Code](https://adventofcode.com/) event puzzles using TypeScript/JavaScript.
3+
This repository contains solutions and a local development environment for the [Advent of Code](https://adventofcode.com/) event puzzles using **TypeScript/JavaScript**.
44

5-
The codes are structured in a way that discusses and walks through the solution steps for the AoC quizzes rather than focusing on AoC's competitive programming.
5+
- The code repository structure follows a way that discusses and walks through the solution steps for the AoC quizzes rather than focusing on AoC's competitive programming.
6+
- The quizzes were solved for fun (unlocking the 2024 AoC Chrismas symbol 🎄) and brain exercise purposes. Therefore, no GPT or AI completion was used for solving, as advised on the AoC website.
7+
- These codes may get occasional optimization updates or solutions using other languages from time to time.
68

79
### 🎄 Advent of Code Quiz Information
810

@@ -20,6 +22,7 @@ The codes are structured in a way that discusses and walks through the solution
2022
- Day 9: Disk Fragmenter [[link]](/src/2024/2024-12-09/README.md)
2123
- Day 10: Hoof It [[link]](/src/2024/2024-12-10/README.md)
2224
- Day 11: Plutonian Pebbles [[link]](/src/2024/2024-12-11/README.md)
25+
- Day 12: Garden Groups [[link]](/src/2024/2024-12-12/README.md)
2326

2427
</details>
2528

@@ -67,6 +70,7 @@ It follows the directory structure:
6770
Each Advent of Code (AOC) event quiz has its folder under **`"/src/<YEAR>/<YYYY-MM-DD>"`** containing:
6871
- **/lib**: Folder containing main quiz solution logic
6972
- **input.txt**: Random quiz input
73+
> _**INFO:** The sample quiz inputs were slightly altered from the original AoC input text and quiz samples as advised on their website_
7074
- **main.ts**: Main program entry point containing quiz answer(s) using random input
7175
- **sample.test.ts**: Minimal sample input with expected correct answers
7276
- **README.md**: Reference and other notes about the AOC quiz question

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"dev": "vitest",
1313
"dev:debug": "vite-node src/sample/sample.ts",
1414
"transpile": "tsc -p tsconfig.json && tsc-alias",
15+
"transpile:noemit": "tsc -p tsconfig.json --noEmit",
1516
"watch": "tsc -p tsconfig.json --watch",
1617
"watch:docker:win": "tsc -p tsconfig.json --watch --watchFile dynamicPriorityPolling --watchDirectory dynamicPriorityPolling",
1718
"lint": "eslint \"src/**/*.ts\" *.mjs *.ts",

src/2024/2024-12-10/lib/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { GridCoordinateSymbol, PointSteps } from './types.js'
88
* @param {number[][]} data - 2D number array containing hiking trail data
99
* @returns {GridCoordinateSymbol} Returns the `poiint` (x,y) coordinate expressed in string and its value
1010
*/
11-
export const getCoordinateSymbol = (point: Point, data: number[][]): GridCoordinateSymbol => {
11+
export const getCoordinateSymbol = (point: Point, data: number[][] | string[][]): GridCoordinateSymbol => {
1212
return {
1313
coordinate: `${point!.x},${point!.y}`,
1414
symbol: data[point!.y]![point!.x] as number

src/2024/2024-12-11/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ Visit the Advent of Code website for more information on this puzzle at:
77

88
## Code
99

10-
### `utils.ts` - contains helper and utility scripts for the quiz.
10+
### `utils.ts`
1111

12+
- contains helper and utility scripts for the quiz.
1213
- `isEvenDigits()` - Checks if a number has an even number of digits
1314
- `halfDigit()` - Divides the number into two (2) separate groups (digits) if they have an even number of digits, each group having half the original number's digits.
1415
- `arrayToObject()` - Converts an array of numbers to an Object, using the array number elements as keys with a default numeric value of `1`

src/2024/2024-12-12/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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
22 KB
Loading
8.25 KB
Loading
15.6 KB
Loading
14.1 KB
Loading

0 commit comments

Comments
 (0)