Skip to content

feat: day 14 restroom redoubt 20241214 #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ This repository contains solutions and a local development environment for the [
- Day 11: Plutonian Pebbles [[link]](/src/2024/2024-12-11/README.md)
- Day 12: Garden Groups [[link]](/src/2024/2024-12-12/README.md)
- Day 13: Claw Contraption [[link]](/src/2024/2024-12-13/README.md)
- Day 14: Restroom Redoubt [[link]](/src/2024/2024-12-14/README.md)

</details>

Expand Down
4 changes: 4 additions & 0 deletions src/2024/2024-12-10/lib/scoresRatings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const findPaths = (pointVector: PointDirection, data: number[][], isRating: bool
if (step === undefined) continue
const pt = getCoordinateSymbol(step, data)

if (pt === undefined) continue

if (pt.symbol === 9) {
if (isRating) {
// Rating: count all trails ending in 9's
Expand Down Expand Up @@ -76,6 +78,8 @@ export const countTrailScores = (data: number[][], params?: InputOptions): Trail
}

const pt = getCoordinateSymbol(starts[i] as Point, data)
if (!pt) continue

activeZeroIndex = pt.coordinate
scores[activeZeroIndex] = []

Expand Down
4 changes: 2 additions & 2 deletions src/2024/2024-12-13/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const data = fileReader('../input.txt')
const data2 = fileReader('../input2.txt')

/**
* Part 1/2 of the 2024-12-14 quiz
* Part 1/2 of the 2024-12-13 quiz
* Counts the number of tokens needed to win all possible prizes.
*/
const quiz20241213_01 = () => {
Expand All @@ -17,7 +17,7 @@ const quiz20241213_01 = () => {
}

/**
* Part 2/2 of the 2024-12-14 quiz
* Part 2/2 of the 2024-12-13 quiz
* Counts the number of tokens needed to win all possible prizes,
* adjusted to the additional `10000000000000` of the prize coordinates
*/
Expand Down
31 changes: 31 additions & 0 deletions src/2024/2024-12-14/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## Day 14: Restroom Redout

Visit the Advent of Code website for more information on this puzzle at:

**Source:** https://adventofcode.com/2024/day/14<br>
**Status:** Complete ⭐⭐

## Code

### `findEasterEgg.ts`

- **`findEasterEgg()`** - Counts the no. of seconds before robots display (form) the Christmas Tree easter egg.
> **NOTE:** I got tips and hints from about the figure of the Christmas tree [here](https://elixirforum.com/t/advent-of-code-2024-day-14/68091/3) after trying to observe for a 🎄 pattern in grid renders per second iteration.

### `safetyFactor.ts`

- **`calculateSafetyFactor()`** - Counts the safety factor after `params.seconds` of simulating moving the robots.

### `board.ts`

**Board** class

- Manages the `Grid`-like 2D string array, methods, and properties in which robots run
- **`create()`** - Creates a blank `this.length` x `this.width` board, clearing
- **`findQuadrants()`** - Finds the four (4) main quadrants of `this.grid`, each containing a set of inclusive `start` and `end` coordinates.
- **`getQuadrant()`** - Finds the quadrant `ID` of a `Point` within the `this.grid` 2D array.
- **`moveRobot()`** - Moves a robot from a tile and updates the current and new tile's robot count
- **`setRobot()`** - Sets a new robot into the `Board`'s robots list and marks its position in `this.grid[][]` array
- **`setTileValue()`** - Sets the string value in the 2D `this.grid[][]` array
- **`simulateRobotsWalk()`** - Move (walk) the robots by updating their positions by velocity by `seconds` times.
- **`viewQuadrants()`** - Draws categorized symbols per quadrant on a temporary 2D array for visualization.
Binary file added src/2024/2024-12-14/assets/sample.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading