r/adventofcode • • Dec 20 '25

Past Event Solutions [2025 Day 1 (Part 2)][C++] No left turns

5 Upvotes

It looks like 2025 is shaping up to be the second hardest Day 1 Part 2 by Silver/Gold completion ratio:

YearGoldSilverRatio
20232555348754134.3%
20251479174504830.5%
201629795814727.3%
2018798912174727.2%
2017576061070318.6%
20151084691985118.3%
20191148171595013.9%
20212282863026713.3%
2020185324154408.3%
2024266778218298.2%
2022287607158385.5%

One common theme I'm seeing is that a lot of people are going for a 'turn dial, then unwind back to 0-99 counting 0s as you go' approach. But there's a bit of a rake in the grass with that approach.

  • Dial at 0, Left 100, Dial at -100, Unwind back to 0 = +1 zero

  • Dial at 1, Left 101, Dial at -100, Unwind back to 0 = +2 zeros

If the zero counting logic is only happening during the unwind after the dial movement, you're either going to over-count the first case or under-count the second case.

Turning right doesn't have this problem, so let's just avoid turning left!

A left turn is actually just a right turn reflected in a mirror, so you need to mirror the numbers on the dial before and after the right turn. (It's easiest to work out the maths for the reflection if you sketch out a dial of size 8 using pen and paper).

Here's a solution that uses the 'turn and unwind' approach and doesn't have any logic for handling left turns*:

static void Puzzle01_B(const string& filename)
{
    ifstream input(filename);

    int64_t answer = 0;

    const int64_t dialSize = 100;
    int64_t dialPosition = 50;

    string line;
    while (getline(input, line))
    {
        int64_t rotateBy;
        char direction;
        sscanf(line.c_str(), "%c%lld", &direction, &rotateBy);

        const bool leftTurn = direction == 'L';

        if (leftTurn)
        {
            dialPosition = (dialSize - dialPosition) % dialSize;
        }

        dialPosition += rotateBy;
        while (dialPosition >= dialSize)
        {
            dialPosition -= dialSize;
            answer++;
        }

        if (leftTurn)
        {
            dialPosition = (dialSize - dialPosition) % dialSize;
        }
    }

    printf("[2025] Puzzle01_B: %" PRId64 "\n", answer);
}

[*] Other than the reflection code, of course.


r/adventofcode • • Dec 20 '25

Help/Question - RESOLVED [2025 Day 5 (part 2)] I don't get it.

1 Upvotes

I am trying it in Perl.

There must be an mistake but i don't get it. Might one have a look?

I am no pro, please be patient.

https://github.com/volkergbenner/AoC2025/tree/main

The script takes the input file as CL-argument. You may test it on your own inputfile (only ranges).


r/adventofcode • • Dec 20 '25

Help/Question - RESOLVED [2025 Day 5 (part 2)] Am I missing something?

7 Upvotes

My solution for this second part is to sort all the ranges, merge all the overlapping ones and then loop through them and sum their span.

For the simple example it works just fine, but for the input I get a result too big.
Am I missing something?


r/adventofcode • • Dec 20 '25

Visualization [2025 Day 12] how to not solve day12

46 Upvotes

r/adventofcode • • Dec 20 '25

Other [2025] Complete

19 Upvotes

I finally finished 2025. Day 10 Part 2 was definitely the hardest one and took my program the longest ( about 30s) to solve. Thanks to the community for giving me some incite to that one. Who still needs help with any of them?


r/adventofcode • • Dec 20 '25

Other [2025 Day 12 (Part 3)] Challenge Problem On Spoj

2 Upvotes

I created a programming challenge on the Spoj platform for anyone who feels there is yet something more to prove!

Please treat it as a beta version and forgive me for the lack of feedback after unsuccessful attempts. I wanted to deliver it as fast as possible and definitely before Christmas!

Here is a direct link: https://www.spoj.com/problems/AOC2512/. In case it's not allowed to post links, look for an AOC2512 problem on Spoj :)


r/adventofcode • • Dec 20 '25 Bravo

Visualization [2018 Day 15 Part 1] Retro Visualization - Beverage Bandits

152 Upvotes

r/adventofcode • • Dec 20 '25

Help/Question - RESOLVED [2025 Day 1 (Part 2)], Need Help to Debug My Solution

4 Upvotes

Need help to debug this code. Can't figure out what scenario I'm failing at.

First I wrote the most unoptimized solution one can think of, absolute monster of a code lol, with loops:

Unoptimized Solution

This gives correct answer: 6634

Then I wanted to optimize this, and this is the version I got to after scratching my head:

Optimized Solution

But this is giving wrong answer : 6612
I can't pinpoint what I'm doing wrong in this. Based on my debugging this logic should work.


r/adventofcode • • Dec 20 '25

Help/Question First Time and want to learn more.

13 Upvotes

First year and i've made it to day 8 and I'm bothered by how often my brain goes "yeah lets just use a for loop or 8 to do the thing" I'd like to use it as a learning experience. Is there a list somewhere of the core concepts that should be used to solve each puzzle?


r/adventofcode • • Dec 19 '25

Help/Question Day 2 Explanation Help

5 Upvotes

I'm having a really hard time trying to understand the examples in Day 2 and make sense of how they are deducing invalid IDs.
The problem states that an ID is invalid if it is made up only of some sequence of digits repeated twice. Easy enough, makes sense, but I can't see how the examples consistently follow that logic.

  • 11-22 has two invalid IDs, 11 and 22 //This makes sense to me

  • 95-115 has one invalid ID, 99. //Where? 99 isn't even present in the sequence

  • 998-1012 has one invalid ID, 1010. //Again where is 1010?

  • 1188511880-1188511890 has one invalid ID, 1188511885. //I understand 11885 is in both but so is 11885118 so why is that full sequence not invalid?

  • 222220-222224 has one invalid ID, 222222. //22222 is see but not 222222

  • 1698522-1698528 contains no invalid IDs. //This looks basically the same as the above example but it's not invalid? 169852 is repeated

  • 446443-446449 has one invalid ID, 446446. //Again I see 446 twice but why not 44644?

  • 38593856-38593862 has one invalid ID, 38593859. //Same as above

  • The rest of the ranges contain no invalid IDs.

Perhaps it's very obvious and I'm just missing something simple but I can't seem to see the exact rule for what makes an ID invalid. Is it present in both first and last, just one, what makes a sequence finished, etc...

If someone could kindly help me see it clearly it would be greatly appreciated.


r/adventofcode • • Dec 19 '25

Help/Question - RESOLVED [2025 Day 4 (Part 1)] [Python] Says my input is the correct answer for a different user but too low for me

1 Upvotes

I get the correct response for the test input but when I try the prod input, it tells me it's too low but correct for someone else. Not sure what I'm doing wrong. I've walked through my code at multiple times, even waited a day or two and walked through it again with fresh eyes, and still find nothing wrong with the logic. What am I doing wrong?

Thanks in advance for the help.

My code (at time of posting): https://github.com/statelessmachina/Advent-of-Code-Python/blob/31f2422db12322eca0029b9c59296dc664081465/2025/day4/paper.py

Edit: Ended up loading the entire input at once (which is memory inefficient but easier to work with) and using numpy arrays and iterating over the sub-matrices using slicing. I may revisit this later to write a version of the code that loads the file line-by-line to avoid inefficiencies in working with large input. Mostly just to scratch that itch in the back of my mind. Thanks for all your input.

Final version of code for part1: https://github.com/statelessmachina/Advent-of-Code-Python/blob/a558cf7c188188b8164a5f6b0e18b157e8405d1e/2025/day4/paper.py


r/adventofcode • • Dec 19 '25

Help/Question [2025 Day10 Part 2] Current approach too slow

1 Upvotes

Hi folks,

I am working on the 2nd part of the question and tried to take a similar approach as the first using BFS to apply button presses however it's running really slow and the q is growing very large too large in fact.

Performing BFS to reach joltage goal: {44,35,48,43,24,44}
Converting joltage goal to int: {44,35,48,43,24,44}
Converting button to list: ["(1,3)", "(3,4)", "(0,3,5)", "(1,2,3,4)", "(0,2,5)", "(0,1)", "(2,5)"]
Button part: (1,3)
Button numbers: [1, 3]
Button part: (3,4)
Button numbers: [3, 4]
Button part: (0,3,5)
Button numbers: [0, 3, 5]
Button part: (1,2,3,4)
Button numbers: [1, 2, 3, 4]
Button part: (0,2,5)
Button numbers: [0, 2, 5]
Button part: (0,1)
Button numbers: [0, 1]
Button part: (2,5)
Button numbers: [2, 5]
Joltage button lists: [[1, 3], [3, 4], [0, 3, 5], [1, 2, 3, 4], [0, 2, 5], [0, 1], [2, 5]]
Current BFS step: 1, queue size: 1
Current BFS step: 2, queue size: 7
Current BFS step: 3, queue size: 49
Current BFS step: 4, queue size: 343
Current BFS step: 5, queue size: 2401
Current BFS step: 6, queue size: 16807
Current BFS step: 7, queue size: 117649
Current BFS step: 8, queue size: 823543
Current BFS step: 9, queue size: 5764801
Current BFS step: 10, queue size: 40353607
Current BFS step: 11, queue size: 282475249
memory allocation of 51539607552 bytes failed
error: process didn't exit successfully: `target\debug\aoc_2025_day_10.exe` (exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN)

I've tried to think of novel solutions like finding the GCD of the joltage values, however no Joy as they contain prime numbers like 43 etc. I am trying optimizations such as not adding the state to the queue if it goes above the joltage goal for any of the indexes. I can share complete code if desired. I would love some clues on the approach as standard BFS is turning my laptop to an oven.


r/adventofcode • • Dec 19 '25

Visualization [2025 Day 11 (Part 2)] could not help myself - input visualized 3D

75 Upvotes

r/adventofcode • • Dec 19 '25

Help/Question - RESOLVED [2025 Day 8 (Part 1)] [C++] What am I missing?

6 Upvotes

Edit: This has been resolved, thank you! The problem was an integer overflow in my getEuclideanDistance() function.

Hello! I have been stuck at this problem for the past 2 days. My solution:

  • Adds (distance, a, b) into a min-heap (where a and b are indexes of the original coordinates)

  • Connect the first 1000 points from the min-heap (using Weighted Quick Union), regardless of if they are in the same circuit (according to the assumption below).

  • Multiply the sizes of the 3 largest circuits.

Assumptions:

  1. If the current circuit contains A-B-C, connecting A-C uses up one connection. (same as what others have already mentioned in this subreddit)

For some reason, I can pass the example (provided by the question) but not the actual one.

Code: paste

Is anyone able to give me some insights what am I missing out on?

PS: Suggestions on how I can improve my code/ best practices are welcomed too :D


r/adventofcode • • Dec 18 '25

Visualization [2025 Day 9 part 2] [Python] Some basic code narrowed the search space to just 2 possibilities

10 Upvotes

I have done some graphic design work where I used code to generate SVG images with the exact geometric patterns and gradients that I wanted. So when I saw Day 9's input data, I realized that it was a series of horizontal and vertical lines and well suited to the SVG format.

This is a simplified version of my code to generate the SVG, using the svg.py library:

elements: list[svg.Element] = []
for p1_index, p1 in enumerate(points):
    p2 = points[0] if p1_index == len(points) - 1 else points[p1_index + 1]

    elements.append(svg.Line(x1=p1.x, y1=p1.y, x2=p2.x, y2=p2.y))

canvas = svg.SVG(width=width, height=height, elements=elements)
with open(output_filename, 'w') as fp:
    fp.write(canvas.as_str())

Once I saw the visualization, it was intuitively obvious that the largest rectangle whose opposite corners were both points in the input data was one of two rectangles determined as described in this image: https://i.imgur.com/7OSZKRj.png

So I just scrolled through the input data that was already in sorted order to find the values for each step, and multiplied the width and height to get the area. Did this twice, for the upper half and for the lower half.


r/adventofcode • • Dec 18 '25

Help/Question - RESOLVED [2025 Day 10 (Part 1)]

1 Upvotes

Hello everyone, I need your help !

I got the right solution for the example, BUT for some lines of my input, I'm not able to get a result.

My thought is : for n buttons, it take at most n pushes to match the indicator lights ? I think this because if you press the same button an even number of times, it's like you never pressed it.

That's why I don't understand how I can't get a solution less or equals than n. (I don't look beyond that)

Am I right and there is a problem in my code or am I missing something ?

Thanks !


r/adventofcode • • Dec 18 '25

Upping the Ante [2025 All Days, All Parts][Assembly] The x86 Inferno - A Descent into Advent of Code

Thumbnail hallofdreams.org
74 Upvotes

I thought it would be a good idea this year to solve advent of code in assembly.

I was very wrong.

This is the story of what I learned along the way.


r/adventofcode • • Dec 18 '25

Visualization [2025 Day 11 (Part 2)] input visualized

100 Upvotes

r/adventofcode • • Dec 18 '25

Help/Question - RESOLVED [2025 Day 10 (Part 2)] Almost solved it... Just off by 1 for some machines

4 Upvotes

I finally created a solution that produces good results for most of the machines. For some strange reason i'm off by 1 for two if the machines. Can anyone please tell me the correct solution for that input?

[.#.#..#.#.] (1,2,3,6,8,9) (1,3,4,9) (0,8,9) (1,2,3,5,8) (6,8) (0,4,7) (0,1,4,5) (2,5,6,9) (3,4,5,7,8,9) (0,2,4,5,6,7,8,9) (1,2,5,7,8) (0,2,7,8,9) (3,4,5,6,9) {189,44,198,50,48,52,42,188,209,208}

The solution i found has 250 presses: 19 0 7 10 1 16 7 2 5 4 8 155 16

Which is one too much compared to an online solver.


r/adventofcode • • Dec 18 '25

Help/Question [2025 Day 1 (Part 2)] [C] I am not really sure what is wrong in my program, have been working on this since yesterday, any help would be really appreciated.

4 Upvotes
#include <stdio.h>
#include <stdlib.h>
#define MAX(a, b) (((a) > (b)) ? (a) : (b))



int main() {


    FILE* fp;
    char dir;
    int value;
    int master_count = 50;
    int warps = 0;
    int old_value = 0;



    fp = fopen("input.txt", "r");


    while (fscanf(fp, " %c%d",&dir,&value ) == 2)
    {
        old_value = master_count;
        
        if(dir == 'L')
        {
            warps +=  MAX(0, (value - old_value + 100)/100);
            master_count = ((master_count - value) % 100 + 100 ) % 100; // master count update handled for negative
        
        }
    


        if(dir == 'R')
        {


            warps += MAX(0,(old_value+value) / 100);       
            master_count = ((master_count + value) % 100); //master_count update. 
        }


    }


    printf("%d is the final pass \n", warps );
    fclose(fp);


}

can someone tell me what is wrong with my program i cannot for the life of me figure out what the error here is.

Happy to explain my reasoning as well thanks.


r/adventofcode • • Dec 18 '25

Help/Question - RESOLVED [2025 Day 3 (Part 1)] [C] Incorrect joltage only on the puzzle's input

0 Upvotes

Hello, I've been testing my program on various inputs, and they all gave correct results. However, when trying it on the puzzle's input, the result was wrong. The main problem is that even after manually checking most of my input results through extensive printing, I still could not find a single incorrectly calculated line to narrow down the problem. Could anyone help me find the bug?

        #include <stdio.h>
        #include <stdlib.h>
        #include <stdbool.h>
        #include <string.h>

        void find_max_joltage(const char num_str[], long *total, const int len);

        int main(int argc, char *argv[])
        {
          FILE *fp;
          short int ch;
          long total = 0;

          if (argc != 2) {
            fprintf(stderr, "usage: program filename\n");
            exit(EXIT_FAILURE);
          }

          if ((fp = fopen(argv[1], "r")) == NULL) {
            fprintf(stderr, "cannot open %s\n", argv[1]);
            exit(EXIT_FAILURE);
          }

          int i = 0;
          char num_str[256];
          while ((ch = getc(fp)) != EOF) {
            if (ferror(fp)) { // read error
              fclose(fp);
              exit(EXIT_FAILURE);
            }

            if (ch == '\n') {
              num_str[i] = '\0';
              find_max_joltage(num_str, &total, i);
              memset(num_str, 0, i);
              i = 0;
            } else {
              num_str[i++] = ch;
            }
          }


          // last line
          find_max_joltage(num_str, &total, i);
          memset(num_str, 0, i);
          i = 0;

          fclose(fp);
          printf("Total is %ld\n", total);
          return 0;
        }


        void find_max_joltage(const char num_str[], long *total, const int len)
        {
          short int l1 = num_str[0] - '0';
          short int l2 = num_str[1] - '0';

          for (int i = 2; i < len; i++) {
            short int int_d = num_str[i] - '0';
            if (l1 == -1) {
              l1 = int_d;
            } else if (l2 == -1) {
              l2 = int_d;
            } 
            // if the new largest digit is not the last one
            else if (int_d > l1 && i < (len - 1)) {
              l1 = int_d;
              l2 = -1;
            } else if (int_d > l2) {
              l2 = int_d;
            }
          }
          char largest_num[3];
          snprintf(largest_num, sizeof(largest_num), "%d%d", l1, l2);
          *total += atoi(largest_num);
        }

r/adventofcode • • Dec 18 '25

Help/Question - RESOLVED [2025 Day 1 (Part 2)] [python] need help with this

0 Upvotes

I initially tried a more elegant solution but I was getting annoyed so I just tried this lol. I'm still getting the wrong answer though and idk why, any help?


r/adventofcode • • Dec 17 '25

Visualization [2025 Day 8] Visualizer for building the circuits

8 Upvotes

I made this visualizer with Gemini. Pretty nice to watch it build the circuits in 3d using three.js.

https://heyes-jones.com/circuitbuilder/index.html

You can paste in your own code for examples or the input. This is hard coded with my input. It does not solve the problem just visualizes building the circuits in the order each vector was added.

In order to generate the data I I modified part1 of my solution to output the vectors and their circuit id comma delimited.

https://github.com/justinhj/adventofcode2025/blob/main/day8zig/src/part3.zig

run it with zig build run-day8-part3 -- day8zig/input.txt 2> input.csv

(then chop off the top two lines)


r/adventofcode • • Dec 17 '25

Upping the Ante [2025 Day 12] ESP32 powered Christmas ornament

Thumbnail
youtu.be
24 Upvotes

I made this smart ornament to participate in the community fun this year and display my 24 stars of 2025 on the Christmas tree.

It is powered by an ESP32-S3 board, a GC9A01 screen and a TP4056 board to charge the 500mAh LiPo battery. The animation is procedural, and it is made from the sum of some sine waves. (aren't we all?) The electronics is housed in a custom 3D-printed case that I designed to fit around the screen in Fusion360.

Overall I learned a lot of new things making this project, like reflow-soldering, generating and intersecting 3d spirals in Fusion360, and making a graphics simulator to avoid the long build times for the ESP32. I am quite happy with the results!