Finish Day 1 Part 2
This commit is contained in:
@@ -1,16 +1,15 @@
|
|||||||
https://adventofcode.com/2025/day/1
|
|
||||||
|
|
||||||
Advent of Code
|
Advent of Code
|
||||||
|
|
||||||
[About][Events][Shop][Settings][Log Out]
|
[About][Events][Shop][Settings][Log Out]
|
||||||
|
|
||||||
Bearmine
|
Bearmine 1*
|
||||||
/*2025*/
|
0.0.0.0:2025
|
||||||
|
|
||||||
[Calendar][AoC++][Sponsors][Leaderboards][Stats]
|
[Calendar][AoC++][Sponsors][Leaderboards][Stats]
|
||||||
|
|
||||||
Our sponsors help make Advent of Code possible:
|
Our sponsors help make Advent of Code possible:
|
||||||
Depot - Happy coding and merry builds from Depot. We keep your pipelines fast, your caches warm, and your logs full of cheer, because the holidays are for shipping joy, not waiting on CI. Ship up to 55x faster with Depot.
|
Jane Street - We're a research-driven trading firm where curious people work together to solve the puzzle of global markets, with offices in NYC, London, Hong Kong, and Singapore. Check out our new JS Advent of FPGA Challenge!
|
||||||
--- Day 1: Secret Entrance ---
|
--- Day 1: Secret Entrance ---
|
||||||
|
|
||||||
The Elves have good news and bad news.
|
The Elves have good news and bad news.
|
||||||
@@ -72,8 +71,41 @@ Because the dial points at 0 a total of three times during this process, the pas
|
|||||||
|
|
||||||
Analyze the rotations in your attached document. What's the actual password to open the door?
|
Analyze the rotations in your attached document. What's the actual password to open the door?
|
||||||
|
|
||||||
To begin, get your puzzle input.
|
Your puzzle answer was 964.
|
||||||
|
|
||||||
|
The first half of this puzzle is complete! It provides one gold star: *
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
You're sure that's the right password, but the door won't open. You knock, but nobody answers. You build a snowman while you think.
|
||||||
|
|
||||||
|
As you're rolling the snowballs for your snowman, you find another security document that must have fallen into the snow:
|
||||||
|
|
||||||
|
"Due to newer security protocols, please use password method 0x434C49434B until further notice."
|
||||||
|
|
||||||
|
You remember from the training seminar that "method 0x434C49434B" means you're actually supposed to count the number of times any click causes the dial to point at 0, regardless of whether it happens during a rotation or at the end of one.
|
||||||
|
|
||||||
|
Following the same rotations as in the above example, the dial points at zero a few extra times during its rotations:
|
||||||
|
|
||||||
|
The dial starts by pointing at 50.
|
||||||
|
The dial is rotated L68 to point at 82; during this rotation, it points at 0 once.
|
||||||
|
The dial is rotated L30 to point at 52.
|
||||||
|
The dial is rotated R48 to point at 0.
|
||||||
|
The dial is rotated L5 to point at 95.
|
||||||
|
The dial is rotated R60 to point at 55; during this rotation, it points at 0 once.
|
||||||
|
The dial is rotated L55 to point at 0.
|
||||||
|
The dial is rotated L1 to point at 99.
|
||||||
|
The dial is rotated L99 to point at 0.
|
||||||
|
The dial is rotated R14 to point at 14.
|
||||||
|
The dial is rotated L82 to point at 32; during this rotation, it points at 0 once.
|
||||||
|
|
||||||
|
In this example, the dial points at 0 three times at the end of a rotation, plus three more times during a rotation. So, in this example, the new password would be 6.
|
||||||
|
|
||||||
|
Be careful: if the dial were pointing at 50, a single rotation like R1000 would cause the dial to point at 0 ten times before returning back to 50!
|
||||||
|
|
||||||
|
Using password method 0x434C49434B, what is the password to open the door?
|
||||||
|
|
||||||
Answer:
|
Answer:
|
||||||
|
|
||||||
|
Although it hasn't changed, you can still get your puzzle input.
|
||||||
|
|
||||||
You can also [Shareon Bluesky Twitter Mastodon] this puzzle.
|
You can also [Shareon Bluesky Twitter Mastodon] this puzzle.
|
||||||
|
|||||||
@@ -66,24 +66,35 @@ class Day1Command extends Command {
|
|||||||
var list = await parseInputFile(fileName);
|
var list = await parseInputFile(fileName);
|
||||||
|
|
||||||
int dialValue = 50;
|
int dialValue = 50;
|
||||||
int combination = 0;
|
int combinationPart1 = 0;
|
||||||
|
int combinationPart2 = 0;
|
||||||
|
|
||||||
for (var instruction in list) {
|
for (var instruction in list) {
|
||||||
switch (instruction.direction) {
|
switch (instruction.direction) {
|
||||||
case Direction.left:
|
case Direction.left:
|
||||||
|
// Count full rotations
|
||||||
|
combinationPart2 += (instruction.amount / 100).floor();
|
||||||
|
|
||||||
|
// Count additive rotations (remainder + previous value)
|
||||||
|
if (dialValue != 0 && (dialValue - (instruction.amount % 100)) <= 0) {
|
||||||
|
combinationPart2++;
|
||||||
|
}
|
||||||
|
|
||||||
// Dial counter-clockwise by amount
|
// Dial counter-clockwise by amount
|
||||||
dialValue -= instruction.amount;
|
dialValue -= instruction.amount;
|
||||||
case Direction.right:
|
case Direction.right:
|
||||||
// Dial clockwise by amount
|
// Dial clockwise by amount
|
||||||
dialValue += instruction.amount;
|
dialValue += instruction.amount;
|
||||||
|
combinationPart2 += (dialValue / 100).floor();
|
||||||
}
|
}
|
||||||
|
|
||||||
dialValue = dialValue % 100;
|
dialValue = dialValue % 100;
|
||||||
if (dialValue == 0) {
|
if (dialValue == 0) {
|
||||||
combination++;
|
combinationPart1++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print("Combination: $combination");
|
print("Combination - part 1: $combinationPart1");
|
||||||
|
print("Combination - part 2: $combinationPart2");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user