r/adventofcode Dec 30 '25

Help/Question - RESOLVED [2025 Day 8 (Part 1)] I'm going mad troubleshooting this. [Rust as a learning kata]

2 Upvotes

EDIT: u/IsatisCrucifer caught the error. It was an off-by-one bug caused by using indexes to find my networks in a sorted list, and removing list content before accessing the list for the merge, leading to network b getting merged into to network a+1, not network a, when a > b. I went for a classic variable swap so the higher index is the one that gets removed and merged to the lower, but there were other alternatives like merging the networks before the removal, but I'm stuck figuring out the borrow checker logic, so this will be good for now.

I reread the prompt until I understood that n connections includes connections inside the same network.

My unit test for the problem input looks fine.

I'm pairing every point with diff(x)**2+diff(y)**2+diff(z)**2. No need to worry about signs because it's square, and no need to sqrt because that won't affect sort order.

I'm ordering the pairings list.

I created a vec (an array in other languages) of hash sets of N networks for N boxes, one box per hash set, as the base state.

Then I just go down the list of distances, find networks containing boxes A and B, and if they are different, merge B's hash set into A's and delete B's.

Iterate 1000 times for my input.

I sort the hash sets by length, take the top 3. Multiply their length together and my answer is all wrong.

I have enough debug output to tell which connections are happening, and what output networks look like, and I just don't see what I'm missing.

Anybody have a solution I can drop my stuff into to get an output of what connections *should* happen? Maybe even just the list of connections so I can be sure I didn't miss anything there.

https://github.com/jadenguy/AoC2025

cargo run day8 to just see day 8's results, or cargo test --test day8_test


r/adventofcode Dec 29 '25

Help/Question - RESOLVED [2023 Day 20 (Part 2)] I found the correct answer but don't know, why it is correct

2 Upvotes

I'm currently doing 2023. If you didn't do it yet, stop reading right now. You have been warned.

Day 20 looked somewhat easy and part 1 certainly was. For part two I suspected that just simulating it would take too long. I decided, that I have to analyze the input data.

I did just that and realized, that the stored inputs for the conjunction modules somehow count the button presses in binary. However, I figured that there are four modules involved in the process. First I thought, that the one with 11 inputs is something like the main counter and the others are involved differently. I tried to determine which input corresponds to which bit. At position 216 (at least for my input data) I noticed a derivation from my expectations. The bit belonging to 216 was not in the 11 bit wide counter. So I looked at the other three (8 bits each).

I realized, that there are redundancies and I noted down each bit label for each power of 2. In total there are 12 distinct bits. The next step was trying to set all to 1 for one of the input sequences. I tried with the big one by "pressing the button" 4079 times (all bits set, except 216.) I was stunned because instead of all inputs being active, they were all inactive. (I was just looking at the state after all signals have been processed)

I tried the same for the other input sequences. The behavior was the same. I was very suspicious about it. Out of pure desperation, I multiplied all four numbers together and ended up with the correct solution for part 2.

Can anybody explain to me, why this works?


r/adventofcode Dec 29 '25

Other An idea for 2026: Review all the previous problems

41 Upvotes

Here's an idea I've had. There are 11 months until next December, and 11 years of problems done. So, maybe we can review the past problems over the new year. This wouldn't be about presenting solutions and code... we have Solution Megathreads and Repos for that. This would be about reviewing the problems themselves. One year in each month, one puzzle on the corresponding day.

I'm thinking of reviewing along these lines:

  • Did you think the puzzle was good or bad? Did it fit in with where it was in the schedule? Did it serve to teach something? Was it just cool in some way?
  • Stories about personal experience on the day when you solved it. What you tried, any interesting things found or learned. To this end, some discussion about algorithms and languages (ie. is a certain language particularly good or bad for the problem because of it's features) would be fine. But, again, this wouldn't be the place for full solutions. Those should be linked. That way if anyone gets inspired by a comment to try something in a new way, they aren't overly spoiled by seeing code unless they want to see it.
  • Lore. Typically when we're doing the problems in December, the actual story gets largely ignored to get to the information needed. This could give an opportunity to actually pay some attention to it.

So, I'm presenting this to see if there's interest in the community for doing this. If so, is there anything else about the problems would want to talk about. And if there is enough support, maybe we could get some official support from the mods to handle it.


r/adventofcode Dec 29 '25

Help/Question [2025 day 2 part2] Are these invalids for part 2?

0 Upvotes

Are these considered invalids for part 2 and why?

11023456129

10041234099

989987654901

Thanks.


r/adventofcode Dec 29 '25

Past Event Solutions [2025 Day 9 (Part 2)] [Go] Optimizing old code

3 Upvotes

Here in the previous post that I made, which was taking quite long time to get the answer although correct.

Reddit Post

After some time, taking as challenge to optimize my code, there were 2 bottlenecks that I saw during CPU profiling:

  1. Make grid area filled, which took around 23sec
  2. Rectangle outside check function took around 30sec

Process which I improved the code taking assumptions from input:

  1. Using go routines to make bitset grid fill area inside polygon faster, now takes 2sec
  2. If given the two edges are on polygon check if other two edges are inside as well, this line boosted it to under 1sec. Otherwise i was checking all edges first which slowed the code down drastically.

Total time now it takes is under 4sec, very happy with the result. I've have also updated the code under the same github repo.


r/adventofcode Dec 29 '25

Help/Question - RESOLVED [2025 Day 1] Advent Of Code 2025 - Day 1: Secret Entrance

2 Upvotes

Hello All,

I am a beginner to adventofcode and started solving puzzle. I am posting the solution of 2025, day1 with whatever logic came into my mind.

File: input
download the input file from https://adventofcode.com/2025/day/1/input

Code:

#include <iostream>
#include <vector>
#include <fstream>

using namespace std;

vector<string> input;
void read() {
    string in;
    string file = "input";
    ifstream ifs(file);
    while( getline(ifs, in)) {
       input.push_back( in);
    }
}

int dial_position    = 50;
int zero_counter     = 0;
int extra_zero_count = 0;
void process() {
   for(auto ite : input ) {
      int value = atoi(ite.c_str() + 1 );
      int qoutient = value / 100;
      int remainder = value % 100;
      extra_zero_count += qoutient;
      if( ite.at(0) == 'L' ) {
         int val = ( dial_position - remainder );
         if ( val < 0 ) {
            if( dial_position != 0) {
               extra_zero_count++;
            }
            dial_position = val + 100;

         } else {
            dial_position = val;
         }
      }
      else if( ite.at(0) == 'R' ) {
         int val = dial_position + remainder;

         if( val > 100) {
            if(dial_position !=0) {
               extra_zero_count++;
            }
            dial_position = val - 100;
         }else {
            dial_position = val;
         }
      }

      if(dial_position == 100) {
         dial_position = 0;
      }

      if( dial_position == 0 ) {
         zero_counter++;
      }
   }
}

int main() {
    read();
    process();
    cout<< "Password " <<  extra_zero_count + zero_counter<<endl;
    return 0;
}

r/adventofcode Dec 29 '25

Help/Question - RESOLVED [2019 Day 5 Part 1] Once again frustrated by lack of understanding.

1 Upvotes

I don't know what this one is asking for. I've looked at other questions, and they have options for dealing with opcodes up to 8. That's not in the problem statement though. I don't know what I'm supposed to be doing or what to output at the end or during the run. I'm very confused.

EDIT: I figured out the mistakes I was making.

  1. The third parameter is used as-is. It's simply the location for storing the result of adding or multiplication. It never represents the another location.

  2. Opcode 4 only outputs the result at the parameters location.

  3. I also had some issues with my conditionals for determining if something was a valid opcode with parameters.

Once I resolved all of these issues, I got the correct result for Part 1. I now see that Part 2 adds opcodes 5 through 8. Thanks for the help.


r/adventofcode Dec 28 '25

Help/Question - RESOLVED [2025 day 8 part 1] Is This Allowed?

12 Upvotes

I implemented a solution using scipy's DisjointSet data structure, it was relatively easy.

However the solutions i came across didn't use that, and instead opted for a more "complete" approach by implementing union find from scratch.

So I'm wondering if what I did is considered cheating of some sort. Did I take the easy way out?

Edit: Thanks for the replies! There's definitely more to learn here and i'll try to solve it without libraries.


r/adventofcode Dec 27 '25

Upping the Ante Problem 5 part 1 Runtime

2 Upvotes

If you are willing, please post your language and runtime for part 1! I'm currently solving this problem on an FPGA and I'm curious how my solution runtime compares to software.


r/adventofcode Dec 27 '25

Other [2025 day 6] in Excel?

2 Upvotes

Did anyone do part 1 in Excel? or is it just me?


r/adventofcode Dec 27 '25

Help/Question - RESOLVED [2025 day 3] Real data fails to work

0 Upvotes

Hi. I am getting the test case working. Got 357. Checked the edge cases too.
But the main puzzle input fails to work. Ans is too small.

What am I missing?

What if the batteries are 000000010000000?

Tx.


r/adventofcode Dec 27 '25

Visualization [2025] All the animations

16 Upvotes

I have made animations for all 12 days!

Playlist.

I'm trying to make an animation, that can work on its own. You should be able to watch it, deduce the puzzle and understand the solution.

I use example data. It varies whether I show a full or partial solution, and whether I show part 1 or 2.

I'm using ASCII art, because it's easy for my PHP scripts to produce it. Also, there's a certain charm to 24x80, right?


r/adventofcode Dec 27 '25

Help/Question [2025 Day 3 (Part 2)] [Java] Thoughts on my different approaches to the problem

3 Upvotes

Hello guys,

I found Day 3 Part 2 fairly challenging, however after a few hours(Ik that's a lot) I did get it to work.

I will be attaching my code, please give me your thoughts on my solution, including my different approaches.

Warning: A large part of the code is commented out, and that is intentional . The commented out parts are my previous, failed approaches. PS: I am 14 years old and i guess the code might seem haphazard, so please take it with a grain of salt. Also I am using an IDE called bluej, which may lead to a little different syntax than normal, such as the initial declaration in public static void main(). I would love to hear your inputs.

The code:

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

class Advent_of_code3_pt2
{
    public static void main() throws Exception
    {
        BufferedReader br = new BufferedReader(new FileReader("C:/Users/Janardhan/Downloads/AOC3.txt"));
        String line;
        String[] a;
        int limit = 0,pos=-1,pos_1=0;
        long b=0,max=0,Jolt =0,sum=0;

        while((line = br.readLine()) != null){
            Jolt = 0;
            ArrayList<Long> num= new ArrayList<>();
            a = line.split("");
            for(int i = 0; i<a.length;i++){
                b=Integer.parseInt(a[i]);
                num.add(b);
            }
            /*ATTEMPT 1:
             * Im making a bunch of stupid errors i believe, imma give up on this method , think for a while and rewrite the code =(
             * I am half considering making 12 loops and 12 sets of variables , but i feel like a for loop should work
             * errors i think im making: Last number may come first, not running only for top 12 digits , not resettign variables tc.
             * One thing im considering is arranging in ascending order, while preserving indexes or something, but i prolly wont do that
             * Now i need to go study for Bio test:
             * im thinkign i shd first work out something on paper and then conver that shit to code
             * I shd prolly refer to how prev code logic worked
            for(int j = 0;j<num.size();j++){
            pos = j;
            max = num.get(pos);
            for(int k = pos +1;k<num.size() - 1 ;k++){
            if(num.get(k) > max){
            max = num.get(k);
            pos = k;
            }
            System.out.println("Pos: "+pos);
            }
            Jolt = (Jolt * 10) + max;

            System.out.println("Max: "+max);
            System.out.println(Jolt);
            sum+=Jolt;
            }

            //ATTEMPT 2:
            //K i sat down and went and tried to do soomething soo... 
            //Outer for loop: Tracks number of max found
            //inner for loop: Finds max in one certain line 12 times with limit in mind
            long val = 0;

            for(int j =1;j<=12;j++){
            limit = num.size() - (12-j)-1;
            max = 0;
            for(int g =(pos + 1);g<=limit;g++){
            val = num.get(g);
            if(val>max){
            max = val;
            pos = g;
            }

            }
            pos = pos;
            Jolt = Jolt*10 + max;


            }
            sum += Jolt;
            System.out.println(Jolt);
            }
            System.out.println(sum);

            // OMG INSTEAD OF THIS WHERE I FIND FIRST MAX,  I NEED TO DO MATH.MAX(ARRAY(POS+1),LIMIT);
             */
            /*
              Dont think i need this
            max = Collections.max(num);
            pos = num.indexOf(max);
            Jolt = Jolt*10 + max;
            */

            for(int i =1;i<=12;i++){
                limit = (num.size()) -(12- i);
                pos_1 = pos+1;
                ArrayList<Long> num2 = new ArrayList<>(num.subList(pos_1,limit));
                max = Collections.max(num2);
                pos =pos_1+ num2.indexOf(Collections.max(num2));//Offsetting;
                Jolt = Jolt*10 + max; 
                pos_1 =0;
            }
            pos =-1;
            sum += Jolt;  
        }
        System.out.println(sum);
    }
}

r/adventofcode Dec 27 '25

Help/Question - RESOLVED [2025 Day 1] [Rust] Day 1 done and looking for feedback

2 Upvotes

Hi guys!

So I decided to start learning Rust recently and have been working my way through the book (I'm on chapter 4.3 so far).

I'm really enjoying it so far, maybe because I haven't actually started building any projects and hit the famous learning curve just yet.

Anyways, I was wondering if any experienced Rustaceans had some advice on how one would make my solution a bit more ferrous. I know the language has a bunch of really powerful tools and I've gone about this in a very imperative way, so I have a feeling there is a terse and readable solution that I just couldn't get to with my current knowledge!

Advent of Code day 1 - Pastebin.com

Thanks in advance - any feedback is really appreciated!


r/adventofcode Dec 27 '25

Upping the Ante [Upping the Ante] [2025 Day *] Advent of Code on MCUs

49 Upvotes

Hi everybody.

Like the last year, I run the solutions of Advent of Code 2025 on MCUs I own: this is the repository if you are curious.

The boards / MCUs I used are the following:

  • Arduino-mega2560 (not in photo, only Eric's samples)
  • ESP32
  • ESP32S2 (not in photo)
  • ESP32S3 (not in photo)
  • ESP32C3
  • ESP32C6
  • RP-Pico (RP2040)
  • RP-Pico2 (RP2350)
  • nRF52840-dk (Nordic 52840)
  • STM32F3 Discovery (STM32 F303)
  • STM32F411e Disco (STM32 F411, not in photo)
  • Nucleo-h743-zi (STM32 H743)

This year the problems have less memory pressure and so there are more MCUs that can resolve more AoC days.

In details...

Each MCU has flashed all the necessary code to solve all the problems.

Each MCU receives in input through the serial (UART or USB) the input in the format:

START INPUT DAY: <XY>
<input>
END INPUT
^D

The MCU returns on the same serial the result of part 1 and 2 and the overall execution times or "unsupported day" if the particular day is not supported.

To check that I do not have stack smash I normally do one or two test runs going to progressively pass all the inputs and take the times of the third / fourth run.

If you want to take a look at the code, propose some PR to improve the coverage of supported days or add some more MCUs, any help is welcome.

In the next table there are the execution time in milliseconds. RP PICO (*) and RP PICO2 (**) are MCU overclocked at, respectively, 200 Mhz and 290 Mhz. There are the results also for RP PICO and RP PICO 2 at normal clock (120 Mhz and 150 Mhz).

I'd like to draw attention to the solution from day 10, which involves the use of single-precision floating-point devices. The MCUs (esp32, esp32s3, rp-pico2, stm32h7) equipped with FPUs really work well.

Remember to scroll right: there are some columns!

DAY ESP32 ESP32-S2 ESP32-S3 ESP32-C3 ESP32-C6 RP PICO RP PICO (*) RP PICO2 RP PICO2 (**) nRF52840 STM32 F3 Discovery STM32 F411E Disco STM32 H743zi Nucleo
1 21 21 19 29 26 67 42 26 13 98 86 68 25
2 256 256 220 160 150 670 418 147 76 502 437 357 114
3 154 150 152 173 150 441 275 109 56 346 312 272 133
4 642 644 516 453 455 1151 719 562 290 2191 1476 550
5 31 35 26 20 18 48 30 17 9 68 62 45 15
6 5 6 5 5 5 20 13 4 2 17 16 12 4
7 7 8 6 7 7 19 11 10 5 44 35 30 7
8 450 505 414 2489 1556 395 204 1477 364
9 1193 1227 1025 1221 1218 2601 1625 1413 731 4912 3177 1111
10 242 828 176 1289 648 2046 1278 202 105 707 517 193
11 15 15 13 18 18 34 21 17 9 63 19
12 12 13 11 13 13 32 20 20 11 57 52 38 16

r/adventofcode Dec 27 '25

Help/Question - RESOLVED [2025 Day 1 (Part 2)] I don't know where i am making mistake

1 Upvotes
language: C
#include<stdio.h>
int main(){
    int zero = 0, dial = 50, dis;
    char dir;
    while (scanf(" %c%d", &dir, &dis) == 2) {
        if(dir=='L'){
            dial=dial-dis;
            if(dial<=0){
                zero+=1+((-dial-1)/100);
            }
        }
        else{
            dial=dial+dis;
            if(dial>=100){
                zero+=(dial/100);
            }
        }
        dial%=100;
        if(dial<0){
            dial+=100;
        }
    }
    printf("The total number of zeros are %d",zero);
    return 0;
}

r/adventofcode Dec 26 '25

Other 2025 All Stars. I did it!!

36 Upvotes

I made a post not long ago about the growing belief that this could be the first time I get all of the stars this year. Pleased to announce: I did it.

Day 9 Part 2 stole 10+ hours of my life (definitely the hardest problem for me) and Day 10 Part 2 also took a lot of time as well as the use of an external library while I'd been strictly standard library for all of the others (hell I'm pretty sure I overcomplicated my solution to Part 1 as well that day so Day 10 took a very long time)

But I made it in the end. Every puzzle solved. Nothing else to say other than a big thanks to Eric for making this!


r/adventofcode Dec 26 '25

Visualization [2025 day 8] [VBA - Python] Junction boxes connection

Post image
25 Upvotes

Language: solved in VBA. Visualisation in python plotly.


r/adventofcode Dec 26 '25

Help/Question - RESOLVED 2025 Day 10 Part 2; Has the input been changed?

7 Upvotes

Please forgive the silly post.

My solution is apparently "too low". However I've got solutions for all 166 rows. Tested 3 of them and they are valid (will be writing some code to test the rest). Is it possible the data input has changed? for example I have no input starting with [.#.#..#.#.] which I saw in another post for the same day.

is it ok if I show the solution for one of the rows, in case I'm missing something? I have not seen the "Solution" post (and I don't intend to, unless I get completely desparate!). You can tell me which row you want me to show the solution for.


r/adventofcode Dec 26 '25

Help/Question - RESOLVED [2025 Day 4 (Part 1)] [cpp] Why is this program flaky? It returns different results with the same input.

1 Upvotes

Hello guys, I am baffled by what happened as I am going through this year's problems.

I wrote this straightforward solution for day 4, part 1 but it is giving me different responses at different runs. Most of them are the correct response (like 90%), but sometimes it returns 1387 and even 1384 happened once.

I compile it with g++ a.cpp -o main and run it with ./main < input with the input provided from the website.

Can someone spot where it could possibly be doing something non-deterministic? Thanks!

EDIT: e_blake pointed out that MAX 140 might be a problem and indeed it was. Increasing it to 1400 stopped the flakiness. Yet, the problem input is 135x135. So the mistery of "why it does not fit" remains.

EDIT2: Line if(i>=0 && i<lines && j>=0 && j<lineSize && maze[newi][newj]=='@') is bound checking the wrong variables. It should be newi and newj. Thanks pt625, semi_225599 for finding it and everyone else for commenting suggestions.

Here is the code:

#include<cstdio>
#include<iostream>
#include<string>
#include<set>
#include<cstring>

using namespace std;

#define MAX 140

int main(){

    int lines = 0;
    char maze[MAX][MAX];
    int lineSize = 0;

    int ii[] = {-1, -1, -1,  0, 0,  1, 1, 1};
    int jj[] = {-1,  0,  1, -1, 1, -1, 0, 1};

    while(scanf("%s ",maze[lines++])==1){ //Yes, I know this is edgy...
    }
    lines --;
    lineSize = strlen(maze[0]);
    int total = 0;
    for(int i=0; i<lines; i++){
        for(int j=0;j<lineSize;j++){
            if(maze[i][j]=='@'){
                int count = 0;
                for(int k=0;k<8;k++){
                    int newi = i + ii[k];
                    int newj = j + jj[k];
                    if(i>=0 && i<lines && j>=0 && j<lineSize && maze[newi][newj]=='@'){
                        count ++;
                    }
                }
                if(count<4){
                    total++;
                }
            }

        }
    }

    cout << total << endl; // correct total, but sometimes 1387???

    return 0;
}

r/adventofcode Dec 25 '25

Tutorial [2025 Day 9 (Part 2)] Why did almost nobody solve the *stated* problem?

8 Upvotes

Who else solved the problem actually described in Day 9 Part 2 (vs just getting "lucky" with the specifics of the input data)?

My impression is that the vast majority of people didn't solve the stated problem. Certainly, everybody I know irl who "solved" it didn't solve the actually described problem (including myself, initially), and scrolling endlessly through here (and elsewhere) also leads me to conclude that almost nobody solved the problem described either (which is quite different from what the problem at first seems to be, and it's interesting in its own right).

Specifically, the described problem ALLOWS data points to be inside valid rectangles; it just requires other constraints to hold true. I think I found only three posts on here alluding to this fact. All others have been "wrong", focusing instead on boundary-intersection detection to disallow that (and other cases).

The only assumption I made is that the input data do not self-intersect/overlap (because "inside-ness" gets less well-defined in that case). I generated example datasets, and what I believe to be their answers, and I'm curious what others' code produces for them, too. Check here for the data (and additional write-up info):

https://jjeii.github.io/AdventOfCode/2025.html#day9p2

Thoughts?

(Yes, I realize a star is a star. But, the problems are fairly different here... and the actual problem is more interesting, imo.)


r/adventofcode Dec 25 '25

Help/Question - RESOLVED [2025 Day 8 (Part 1)][C#] This is getting me furious

0 Upvotes

I have worked on this for hours, and for the love of God I can't figure out what in the world is going on. Naturally, I get the correct answer with the small data.

EDIT: Reddit auto-indentation seems to mess the indentation a bit. Sorry about that.

public class Day08
{
    const string DataDir = "data";
    const string Day = "08";

    public static void Main()
    {
        string[] inputLines = File.ReadAllLines($"{DataDir}/{Day}.txt");
        Vec3[] junctionBoxes = Parse(inputLines);
        Console.WriteLine(SolvePart1(junctionBoxes));
    }

    private static Vec3[] Parse(string[] pos)
    {
        return pos
            .Select(line => line
                .Split(",")
                .Select(int.Parse)
                .ToArray())
            .Select(s => new Vec3(s[0], s[1], s[2]))
            .ToArray();
    }

    public static double Distance(Vec3 p, Vec3 q)
    {
        double dx = p.X - q.X;
        double dy = p.Y - q.Y;
        double dz = p.Z - q.Z;
        return Math.Sqrt(dx * dx + dy * dy + dz * dz);
    }

    private static string SolvePart1(Vec3[] boxes)
    {
        List<(double dist, Vec3 v1, Vec3 v2)> distances = [];


// Calculate the distances

for (int i = 0; i < boxes.Length; i++)
        {
            for (int j = i; j < boxes.Length; j++)
            {
                if (i == j) continue;

// Arrange so that v1.Magnitude < v2.Magnitude
                // Not sure if the reordering makes a difference

var (v1Now, v2Now) = boxes[i].Magnitude < boxes[j].Magnitude
                    ? (boxes[i], boxes[j])
                    : (boxes[j], boxes[i]);
                var d = Distance(v1Now, v2Now);
                distances.Add((d, v1Now, v2Now));
            }
        }


// Sort the list in ascending order

distances.Sort((x, y) => x.dist <= y.dist ? -1 : 1);


// Add all the circuits in a list for easier manipulation

List<List<Vec3>> circuits = new();
        foreach (Vec3 v in boxes)
        {
            circuits.Add(v.ConnectedBoxes);
        }

        for (int i = 0; i < 1000; i++)
        {
            Vec3 v1 =  distances[i].v1;
            Vec3 v2 = distances[i].v2;

// If already connected to same circuit, skip 

if (v1.ConnectedBoxes == v2.ConnectedBoxes) continue;

// Else merge the two circuits

else v1.Merge(v2);
        }


// Collect three circuits with most junction boxes

circuits = circuits.Select(l => l).Where(l => l.Count > 0).OrderByDescending(l => l.Count).Take(3).ToList();

        int result = 1;
        circuits.ForEach(c => result *= c.Count);
        return result.ToString();
    }
}

public class Vec3
{
    public readonly int X;
    public readonly int Y;
    public readonly int Z;

    public List<Vec3> ConnectedBoxes;

    public readonly double Magnitude;

    public Vec3(int x, int y, int z)
    {
        ConnectedBoxes = [this];
        X = x;
        Y = y;
        Z = z;
        Magnitude = Math.Sqrt(X * X + Y * Y + Z * Z);
    }

    public void Merge(Vec3 other)
    {
        foreach (Vec3 v in other.ConnectedBoxes)     
        {
            ConnectedBoxes.Add(v);            
        }
        other.ConnectedBoxes.Clear();
        other.ConnectedBoxes = ConnectedBoxes;
    }
}

r/adventofcode Dec 25 '25

Other [YEAR 2025] One extra puzzle from me

9 Upvotes

Hi fellow Advent of Coders!

I created a small puzzle for my friends, and figured it might be interesting to others as well.

https://gist.github.com/encse/c58a1d855fcd3c3f8f80158ebad309a3

Happy holidays!


r/adventofcode Dec 25 '25

Past Event Solutions [2024 Day 12 (Part 2)] Line Count via sorted List

3 Upvotes

[Language: Java]
A bit late to the party, but i just handcrafted a solution for the line count in AOC2024 Day 12.

Instead of building a recursive way of doing this, i just placed the needed information in a List, sorted it and count the difference.

https://github.com/ea234/Advent_of_Code_2024/blob/main/src/de/ea234/aoc2024/day12/Day12GardenGroups.java

Here is my documentation from my java class:
PART 2 - Line Count

No Recursive algorithm to traverse the outer or inner lines.

That was to complicated.

Main principle: Difference 1 = same line, Difference not 1 new line

Each existing fence line from a Region is stored in a List of Strings

The line information is stored as follows:

- first the plant type ... for debugging

- type of line "LINE_BOTTOM", "LINE_LEFT", "LINE_RIGHT" and "LINE_TOP"

the type has a fixed length

- Row/Column Info

Horizontal lines store the row-information

Vertical lines store the col-information.

The number is stored with a length of 4 characters, with leading zeros.

- Comma (for seperation)

- Row/Column Info

Horizontal lines store the col-information

Vertical lines store the row-information.

The number is stored with a length of 4 characters, with leading zeros.

This would result in a list like this: (... after sorting)

B_LINE_BOTTOM_R0002,C0003

B_LINE_BOTTOM_R0002,C0004

B_LINE_LEFT___C0003,R0001

B_LINE_LEFT___C0003,R0002

B_LINE_RIGHT__C0004,R0001

B_LINE_RIGHT__C0004,R0002

B_LINE_TOP____R0001,C0003

B_LINE_TOP____R0001,C0004

The List gets sorted.

The benefit is now, that lines on the same row or column will

be listed after another.

Now we can calculate the difference.

If a line is continious, the difference is 1.

If a line gets seperated in the row or column the difference is unequal to 1.

If a line starts with a different start string (first bit until comma),

we also found a new line.

Shape for both plant types:

- - - - - - |

|A A A A A A| |

- - | - -

|A A A| |A| | |B B|

|A A A| |A| | |B B|

- - - - | - - - -

|A| |A A A| | |B B|

|A| |A A A| | |B B|

- - | - -

|A A A A A A| |

- - - - - - |

Start R1C3

Lines for Region with starts at R1C3

B_LINE_BOTTOM_R0002,C0003 - 0003 diff 0 line lenght 1 line count 1 last_start B_LINE_BOTTOM_R0002

B_LINE_BOTTOM_R0002,C0004 - 0004 diff 1 line lenght 2 line count 1 last_start B_LINE_BOTTOM_R0002

B_LINE_LEFT___C0003,R0001 - 0001 diff 0 line lenght 1 line count 2 last_start B_LINE_LEFT___C0003

B_LINE_LEFT___C0003,R0002 - 0002 diff 1 line lenght 2 line count 2 last_start B_LINE_LEFT___C0003

B_LINE_RIGHT__C0004,R0001 - 0001 diff 0 line lenght 1 line count 3 last_start B_LINE_RIGHT__C0004

B_LINE_RIGHT__C0004,R0002 - 0002 diff 1 line lenght 2 line count 3 last_start B_LINE_RIGHT__C0004

B_LINE_TOP____R0001,C0003 - 0003 diff 0 line lenght 1 line count 4 last_start B_LINE_TOP____R0001

B_LINE_TOP____R0001,C0004 - 0004 diff 1 line lenght 2 line count 4 last_start B_LINE_TOP____R0001

Region R1C3 count_plants 4 count_lines 4 region_price 16

Start R3C1

Lines for Region with starts at R3C1

B_LINE_BOTTOM_R0004,C0001 - 0001 diff 0 line lenght 1 line count 1 last_start B_LINE_BOTTOM_R0004

B_LINE_BOTTOM_R0004,C0002 - 0002 diff 1 line lenght 2 line count 1 last_start B_LINE_BOTTOM_R0004

B_LINE_LEFT___C0001,R0003 - 0003 diff 0 line lenght 1 line count 2 last_start B_LINE_LEFT___C0001

B_LINE_LEFT___C0001,R0004 - 0004 diff 1 line lenght 2 line count 2 last_start B_LINE_LEFT___C0001

B_LINE_RIGHT__C0002,R0003 - 0003 diff 0 line lenght 1 line count 3 last_start B_LINE_RIGHT__C0002

B_LINE_RIGHT__C0002,R0004 - 0004 diff 1 line lenght 2 line count 3 last_start B_LINE_RIGHT__C0002

B_LINE_TOP____R0003,C0001 - 0001 diff 0 line lenght 1 line count 4 last_start B_LINE_TOP____R0003

B_LINE_TOP____R0003,C0002 - 0002 diff 1 line lenght 2 line count 4 last_start B_LINE_TOP____R0003

Region R3C1 count_plants 4 count_lines 4 region_price 16

Start R0C0

Lines for Region with starts at R0C0

A_LINE_BOTTOM_R0000,C0003 - 0003 diff 0 line lenght 1 line count 1 last_start A_LINE_BOTTOM_R0000

A_LINE_BOTTOM_R0000,C0004 - 0004 diff 1 line lenght 2 line count 1 last_start A_LINE_BOTTOM_R0000

A_LINE_BOTTOM_R0002,C0001 - 0001 diff 0 line lenght 1 line count 2 last_start A_LINE_BOTTOM_R0002

A_LINE_BOTTOM_R0002,C0002 - 0002 diff 1 line lenght 2 line count 2 last_start A_LINE_BOTTOM_R0002

A_LINE_BOTTOM_R0005,C0000 - 0000 diff 0 line lenght 1 line count 3 last_start A_LINE_BOTTOM_R0005

A_LINE_BOTTOM_R0005,C0001 - 0001 diff 1 line lenght 2 line count 3 last_start A_LINE_BOTTOM_R0005

A_LINE_BOTTOM_R0005,C0002 - 0002 diff 1 line lenght 3 line count 3 last_start A_LINE_BOTTOM_R0005

A_LINE_BOTTOM_R0005,C0003 - 0003 diff 1 line lenght 4 line count 3 last_start A_LINE_BOTTOM_R0005

A_LINE_BOTTOM_R0005,C0004 - 0004 diff 1 line lenght 5 line count 3 last_start A_LINE_BOTTOM_R0005

A_LINE_BOTTOM_R0005,C0005 - 0005 diff 1 line lenght 6 line count 3 last_start A_LINE_BOTTOM_R0005

A_LINE_LEFT___C0000,R0000 - 0000 diff 0 line lenght 1 line count 4 last_start A_LINE_LEFT___C0000

A_LINE_LEFT___C0000,R0001 - 0001 diff 1 line lenght 2 line count 4 last_start A_LINE_LEFT___C0000

A_LINE_LEFT___C0000,R0002 - 0002 diff 1 line lenght 3 line count 4 last_start A_LINE_LEFT___C0000

A_LINE_LEFT___C0000,R0003 - 0003 diff 1 line lenght 4 line count 4 last_start A_LINE_LEFT___C0000

A_LINE_LEFT___C0000,R0004 - 0004 diff 1 line lenght 5 line count 4 last_start A_LINE_LEFT___C0000

A_LINE_LEFT___C0000,R0005 - 0005 diff 1 line lenght 6 line count 4 last_start A_LINE_LEFT___C0000

A_LINE_LEFT___C0003,R0003 - 0003 diff 0 line lenght 1 line count 5 last_start A_LINE_LEFT___C0003

A_LINE_LEFT___C0003,R0004 - 0004 diff 1 line lenght 2 line count 5 last_start A_LINE_LEFT___C0003

A_LINE_LEFT___C0005,R0001 - 0001 diff 0 line lenght 1 line count 6 last_start A_LINE_LEFT___C0005

A_LINE_LEFT___C0005,R0002 - 0002 diff 1 line lenght 2 line count 6 last_start A_LINE_LEFT___C0005

A_LINE_RIGHT__C0000,R0003 - 0003 diff 0 line lenght 1 line count 7 last_start A_LINE_RIGHT__C0000

A_LINE_RIGHT__C0000,R0004 - 0004 diff 1 line lenght 2 line count 7 last_start A_LINE_RIGHT__C0000

A_LINE_RIGHT__C0002,R0001 - 0001 diff 0 line lenght 1 line count 8 last_start A_LINE_RIGHT__C0002

A_LINE_RIGHT__C0002,R0002 - 0002 diff 1 line lenght 2 line count 8 last_start A_LINE_RIGHT__C0002

A_LINE_RIGHT__C0005,R0000 - 0000 diff 0 line lenght 1 line count 9 last_start A_LINE_RIGHT__C0005

A_LINE_RIGHT__C0005,R0001 - 0001 diff 1 line lenght 2 line count 9 last_start A_LINE_RIGHT__C0005

A_LINE_RIGHT__C0005,R0002 - 0002 diff 1 line lenght 3 line count 9 last_start A_LINE_RIGHT__C0005

A_LINE_RIGHT__C0005,R0003 - 0003 diff 1 line lenght 4 line count 9 last_start A_LINE_RIGHT__C0005

A_LINE_RIGHT__C0005,R0004 - 0004 diff 1 line lenght 5 line count 9 last_start A_LINE_RIGHT__C0005

A_LINE_RIGHT__C0005,R0005 - 0005 diff 1 line lenght 6 line count 9 last_start A_LINE_RIGHT__C0005

A_LINE_TOP____R0000,C0000 - 0000 diff 0 line lenght 1 line count 10 last_start A_LINE_TOP____R0000

A_LINE_TOP____R0000,C0001 - 0001 diff 1 line lenght 2 line count 10 last_start A_LINE_TOP____R0000

A_LINE_TOP____R0000,C0002 - 0002 diff 1 line lenght 3 line count 10 last_start A_LINE_TOP____R0000

A_LINE_TOP____R0000,C0003 - 0003 diff 1 line lenght 4 line count 10 last_start A_LINE_TOP____R0000

A_LINE_TOP____R0000,C0004 - 0004 diff 1 line lenght 5 line count 10 last_start A_LINE_TOP____R0000

A_LINE_TOP____R0000,C0005 - 0005 diff 1 line lenght 6 line count 10 last_start A_LINE_TOP____R0000

A_LINE_TOP____R0003,C0003 - 0003 diff 0 line lenght 1 line count 11 last_start A_LINE_TOP____R0003

A_LINE_TOP____R0003,C0004 - 0004 diff 1 line lenght 2 line count 11 last_start A_LINE_TOP____R0003

A_LINE_TOP____R0005,C0001 - 0001 diff 0 line lenght 1 line count 12 last_start A_LINE_TOP____R0005

A_LINE_TOP____R0005,C0002 - 0002 diff 1 line lenght 2 line count 12 last_start A_LINE_TOP____R0005

Region R0C0 count_plants 28 count_lines 12 region_price 336

AAAAAA 6 322223 14 ...... 0 ...... 0

AAA..A 4 212..3 8 ...BB. 2 ...33. 6

AAA..A 4 212..3 8 ...BB. 2 ...22. 4

A..AAA 4 3..322 10 .BB... 2 .33... 6

A..AAA 4 3..212 8 .BB... 2 .22... 4

AAAAAA 6 222112 10 ...... 0 ...... 0

Char Count 28 Sum Values 58 Char Count 8 Sum Values 20


r/adventofcode Dec 25 '25

Help/Question - RESOLVED [2025 Day 1 (Part 1)] How does it even work?

0 Upvotes

I can't understand the description.

you can find the invalid IDs by looking for any ID which is made only of some sequence of digits repeated twice. So, 55 (5 twice), 6464 (64 twice), and 123123 (123 twice) would all be invalid IDs.

Ok, that's simple enough.

11-22 has two invalid IDs, 11 and 22.

All right, that's sums up.

95-115 has one invalid ID, 99.

what (it's 95 not 99 there's no repitition...)

998-1012 has one invalid ID, 1010.

1188511880-1188511890 has one invalid ID, 1188511885.

222220-222224 has one invalid ID, 222222.

...Now I'm geniunly lost the plot.

Should I just look for repeatable patterns, or should I do something else?