diff --git a/puzzle/2025/01/prompt.html b/puzzle/2025/01/prompt.html index 708cc5e..8758fe7 100644 --- a/puzzle/2025/01/prompt.html +++ b/puzzle/2025/01/prompt.html @@ -87,10 +87,10 @@ on Mastodon. --> -

Advent of Code

buhman

      /*2025*/

+

Advent of Code

buhman 2*

   int y=2025;

@@ -137,12 +137,35 @@ L82

Because the dial points at 0 a total of three times during this process, the password in this example is 3.

Analyze the rotations in your attached document. What's the actual password to open the door?

-

To begin, get your puzzle input.

-

Answer:

+

Your puzzle answer was 1011.

--- 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:

+ +

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?

+
+

Your puzzle answer was 5937.

Both parts of this puzzle are complete! They provide two gold stars: **

+

At this point, you should return to your Advent calendar and try another puzzle.

+

If you still want to see it, you can get your puzzle input.

You can also this puzzle.

diff --git a/src/main.c b/src/main.c index 96970cc..a279f5b 100644 --- a/src/main.c +++ b/src/main.c @@ -93,11 +93,11 @@ int main() ////////////////////////////////////////////////////////////////////// int input_width; - int input_length = puzzle_2025_01_input_size; uint texture_input = rectangularize_input(puzzle_2025_01_input_start, puzzle_2025_01_input_size, &input_width); int input_height = input_width; + int input_length = puzzle_2025_01_input_size; uint texture_framebuffer = make_texture(NULL, GL_RGBA32F, diff --git a/src/shader/day1.fs.glsl b/src/shader/day1.fs.glsl index 1c09957..4d96f02 100644 --- a/src/shader/day1.fs.glsl +++ b/src/shader/day1.fs.glsl @@ -42,27 +42,34 @@ vec2 parse_integer(float ix) vec2 parse_direction(float ix) { float c = get_input(ix); - float left = (c == ascii_l) ? 1.0 : 0.0; - return vec2(ix + 1.0, left); + float direction = (c == ascii_l) ? -1.0 : 1.0; + return vec2(ix + 1.0, direction); } -vec2 simulate_movement(float ix, float position) +vec3 simulate_movement(float ix, float position) { vec2 dir_result = parse_direction(ix); ix = dir_result.x; - float left = dir_result.y; + float direction = dir_result.y; vec2 int_result = parse_integer(ix); ix = int_result.x; float number = int_result.y; - if (left == 1.0) { - position = position - number; - } else { - position = position + number; + float old_position = position; + float crossings = floor(number / 100.0); + position += direction * mod(number, 100.0); + if (position < 0.0) { + position += 100.0; + crossings += float(old_position != 0.0); } - position = mod(position, 100); - return vec2(ix, position); + if (position > 99.0) { + position -= 100.0; + crossings += float(position != 0.0); + } + crossings += float(position == 0.0); + + return vec3(ix, position, crossings); } void main() @@ -70,16 +77,18 @@ void main() float ix = 0.0; float position = 50.0; float zeros = 0.0; + float zero_crossings = 0.0; while (ix < input_length) { - vec2 result = simulate_movement(ix, position); + vec3 result = simulate_movement(ix, position); ix = result.x; position = result.y; + zero_crossings += result.z; if (position == 0.0) { zeros += 1.0; } } - fragment_color = vec4(position, zeros, 0, 0); + fragment_color = vec4(zeros, zero_crossings, 0, 0); }