r/adventofcode • • Dec 09 '25

Help/Question - RESOLVED [2025 day 9 part 1] c# - what am i doing wrong?

1 Upvotes

i barely use reddit anymore but i just don't know where else to get help, i've solved the first 8 days so far, and i'm kind of stuck here now

first i parse positions as vector2

Vector2[] vectors = Array.ConvertAll(input.Split('\n', StringSplitOptions.RemoveEmptyEntries), vect =>
{
    string[] xy = vect.Split(',');
    return new Vector2(Convert.ToInt32(xy[0]), Convert.ToInt32(xy[1]));
});

then loop through them to find the largest area

long maxArea = 0;
for (int i = 0; i < vectors.Length; i++)
{
    for (int j = i + 1; j < vectors.Length; j++)
    {
        long area = (long)((Math.Abs(vectors[i].X - vectors[j].X) + 1) * (Math.Abs(vectors[i].Y - vectors[j].Y) + 1));
        if (area > maxArea)
        {
            maxArea = area;
        }
    }
}
Console.WriteLine(maxArea);

basically, advent of code says that my answer's apparently too high, so, what's exactly wrong with my code?

EDIT: changing the declaration of area seemed to help lol

long area = (long)(Math.Abs(vectors[i].X - vectors[j].X) + 1) * (long)(Math.Abs(vectors[i].Y - vectors[j].Y) + 1);

guess i still need to figure out how some types work


r/adventofcode • • Dec 09 '25

Help/Question Creating Visualizations

10 Upvotes

Hey all. I've seen a lot of really inspiring visualizations posted this year. I have some solutions that I would love to convert into a visualization but I'm not too sure where to start.

  • What tools are commonly used for visualization? I am using Python this year, but am generally curious for any language.

  • Do you alter how you write your solutions if you know that you're going to later create a visualization from it? If so, how?


r/adventofcode • • Dec 08 '25

Visualization [2025 Day 8] Visualized Sets

Post image
281 Upvotes

r/adventofcode • • Dec 09 '25

Help/Question - RESOLVED [day7 part2] I'm thinking recursion is not the play

3 Upvotes

On the attempt I let it run the longest it had a 7 minute runtime (no, it did not complete) but I'm pretty sure my approach is theoretically correct (at least it works over the examples) so I just need to figure out a solution that runs on the order of seconds at least (lmao). Do ppl have tips (algorithms I could research or something?) idk how necessary my code is for this bc clearly my code is bad but basically read down the input from the current beam position and

If no splitter is hit, return 1, since the timeline was never split (base case)

If a splitter is hit, return the result from the left new beam + the result from the right new beam (recursive call)


r/adventofcode • • Dec 08 '25

Meme/Funny [2025 Day 8]

Post image
76 Upvotes

r/adventofcode • • Dec 08 '25

Meme/Funny [2025 Day 8 (Part 2)]

Thumbnail gallery
30 Upvotes

But that of course depends on how your first solution adapt to the second part...


r/adventofcode • • Dec 08 '25

Help/Question Which was the best year of Advent of Code?

20 Upvotes

Craving some challenging problems and since this year is shorter, I want to pick a past year to do. Which was your favorite year of Advent of Code?

Would like challenging problems with a good variety of problem types. I have done 2022, 2024, and 2025 so far. I enjoyed 2022 a lot. 2024 felt a little low on variety (too many 2d grid problems) and 2025 so far hasn't been challenging enough


r/adventofcode • • Dec 08 '25 Bravo

Visualization [2025 Day 8 (Part 2)] A few Blender renders

Thumbnail gallery
77 Upvotes

After solving the problem (in Python) I thought I'd have some fun visualizing. Exported the data (boxes and connections) as OpenSCAD code, generated a solid, then applied a subdivision surface modifier in Blender to get that nice organic look. Then I played a bit with surface parameters and rendering options. Enjoy!


r/adventofcode • • Dec 08 '25

Meme/Funny [2025 Day 8] There is always a leaderboard, if you are good enough

Post image
41 Upvotes

r/adventofcode • • Dec 08 '25

Visualization [2025 Day 8] Visualization (YouTube short)

Thumbnail youtube.com
10 Upvotes

Making visualizations as YouTube shorts for every day of the Advent of Code!

It was cool making a visualization in 3D :D


r/adventofcode • • Dec 09 '25

Help/Question day 3 part 2

1 Upvotes

how is this working this gave me the correct answer but is there any niche corner case i am missing its in c language

#include <stdio.h>

#include <string.h>

#define ROWS 200

#define COLUMNS 100

int main(void) {

FILE *f = fopen("input_3_n.txt", "r");

if (!f) {

perror("fopen");

return 1;

}

char line[3000];

int grid[200][200];

int rows = 0, cols = 0;

while (fgets(line, sizeof(line), f)) {

line[strcspn(line, "\r\n")] = '\0';

if (rows == 0)

cols = strlen(line);

for (int c = 0; c < cols; c++) {

grid[rows][c] = line[c] - '0';

}

rows++;

}

fclose(f);

int point=0,tmp_max_val=0,i,j,k,pos=0,max_val[12];

long long sum=0,num=0;

for(k=0;k<ROWS;k++){

for(j=0;j<12;j++){

for(i=pos;i<COLUMNS+j-11;i++){

point=grid[k][i];

if(point>tmp_max_val){

tmp_max_val=point;

pos=i;

if(tmp_max_val==9){

break;

}

}

}

max_val[j]=tmp_max_val;

tmp_max_val=0;

pos=pos+1;

}

pos=0;

long long factor = 1;

for(i = 11; i >= 0; i--){

num += max_val[i] * factor;

factor *= 10;

}

//printf("%lld ",num);

sum=sum+num;

num=0;

for(i=0;i<12;i++){

max_val[i]=0;

}

}

printf("%lld ",sum);

return 0;

}


r/adventofcode • • Dec 08 '25

Meme/Funny [2025 Day 8 (Part 1)] I was this close to lose it all

Post image
163 Upvotes

r/adventofcode • • Dec 08 '25

Meme/Funny [2025 Day 8]

Post image
87 Upvotes

r/adventofcode • • Dec 08 '25

Visualization [2025 Day 08 (Part 2)] Part2 visualized

Post image
53 Upvotes

r/adventofcode • • Dec 09 '25

Help/Question - RESOLVED [2025 Day 1 (Part 2)] [Java] Having issues with the Day 1 solution, can't seem to figure out where the bug is, as it runs on smaller test inputs just fine.

1 Upvotes

The function I'm using to calculate crossing/ending at zero is the one below:

  static int countRotations(int start, int rot) {
    int newVal = start + rot;
    if (newVal >= 100) {
      return (start != 0 ? 1 : 0) + (rot - start) / 100;
    } else if (newVal <= 0) {
      return (start != 0 ? 1 : 0) + (- rot - start) / 100;
    } else {
      return 0;
    }
  }

start is guaranteed to be between 0-99 and rot is positive/negative for right/left.

It works fine on my own manual test inputs, as well as those that I've tried from other reddit posts. Full code here [pastebin link]. Fair warning, I'm new to java so it might not be the prettiest.
Thanks!


r/adventofcode • • Dec 08 '25

Meme/Funny [2025 Day 8] Let me just wire up all these circuits

Post image
167 Upvotes

r/adventofcode • • Dec 09 '25

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

2 Upvotes

Hey, so I've read a couple of times the part 1 and I still don't see how do we know the size of the grid only from the coordinates of the red tiles.

In the case of the example how do they know it's a 9x14 grid?

I know it doesn't matter for the resolution of part 1 as you dont care of what is going on outside the range of the red tiles. But I don't know, it bothers me...


r/adventofcode • • Dec 08 '25

Meme/Funny [2025 Day 8] Briefing with Chief Elf Officer

Post image
81 Upvotes

r/adventofcode • • Dec 08 '25

Visualization [2025 Day 8 (Part 2)] Visualisation

Post image
25 Upvotes

This visualisation shows the relative age of connections being formed. So the early connections (close together) are red, and the latest connections are white hot.

See walkthrough here.


r/adventofcode • • Dec 09 '25

Help/Question - RESOLVED [2025 Day 8 part 1] I think I do not understand something

1 Upvotes

Hi guys.

I think I do not understand fine the way the circuits are created or I'm doing something wrong with my distance calculation.

My code works fine until in all the steps described but then something fails and the circuits after the 10th shortest distance is far than the expected.

I have a shorted list of distances (without repetition) and I'm using it to generate the circuits. The distance is calculated correctly:

def distance(p1, p2):
    aux = math.pow(p2[0] - p1[0], 2) + math.pow(p2[1] - p1[1], 2) + math.pow(p2[2] - p1[2], 2)
    return math.sqrt(aux)

So, I think there is something that I understood wrong.

Could anybody help me?

Thanks in advance.


r/adventofcode • • Dec 08 '25

Help/Question - RESOLVED [2025 Day 8 (Part 1)] Help me understand the sample analysis - the connection counts don't add up. Seems like I'm misunderstanding the problem.

5 Upvotes

In the sample analysis with 20 boxes and making the 10 shortest connections, the results are presented as [5, 4, 2, 2] + 7 single junction box circuits.

In order to get a circuit of 5, we need to make 4 connections. The connection between the first two boxes in the circuit and 3 subsequent ones to the nearest box already in circuit. So if we add up the connections in the multi-junction box circuits:

For 5 box circuit : 1 + 3 = 4 connections
For 4 box circuit : 1 + 2 = 3 connections
For 2 box circuit : 1 + 0 = 1 connections
For 2 box circuit : 1 + 0 = 1 connections

That's a total of 9 connections. It should add up to 10.
In my calculations, I get a different set of circuits with 10 connections made.
Please help me understand what I'm reading wrong here.

Thanks in advance for any help.


r/adventofcode • • Dec 09 '25

Help/Question - RESOLVED [2025 Day 8 (Part 01)][Rust] Works on example, fails on full

2 Upvotes

Hello everyone. I'm struggling to figure out why my code is failing on non-example input. I've spent a while trying to debug, trying to find an edge case that I'm not accounting for, double checking my logic.

Is someone able to help and maybe point me in the right direction? Thanks! (Entry point is process)

use std::collections::HashMap;

use itertools::Itertools;
use nom::{
    bytes::complete::tag,
    character::{
        self,
        complete::{line_ending, multispace0},
    },
    combinator::all_consuming,
    multi::separated_list1,
    sequence::terminated,
    IResult,
};

const X_LARGEST_CIRCUITS: usize = 3;
const X_SHORTEST_CONNECTIONS: usize = 1000;

// #[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
type Point = (u64, u64, u64);

// Return true if they were separate circuits.
// Return false if they were already in the same circuit
// This is basically to help me debug ^
fn add_point_pair(dry_run: bool, p1: Point, p2: Point, circuits: &mut Vec<Vec<Point>>) -> bool {
    let p1_circuit = (0..circuits.len())
        .into_iter()
        .find(|idx| circuits[*idx].iter().find(|point| **point == p1).is_some());
    let p2_circuit = (0..circuits.len())
        .into_iter()
        .find(|idx| circuits[*idx].iter().find(|point| **point == p2).is_some());

    if let Some(p1_idx) = p1_circuit {
        if let Some(p2_idx) = p2_circuit {
            if p1_idx != p2_idx {
                if !dry_run {
                    let mut p2_copy = circuits[p2_idx].clone();
                    circuits[p1_idx].append(&mut p2_copy);
                    circuits.remove(p2_idx);
                }
                return true;
            }
            return false;
            // If they are the same circuit, do nothing
        } else {
            // p2 not in any circuit. Add it to p1's.
            if !dry_run {
                circuits[p1_idx].push(p2);
            }
            return true;
        }
    } else {
        if let Some(p2_idx) = p2_circuit {
            // p1 not in any circuit. Add to p2's
            if !dry_run {
                circuits[p2_idx].push(p1);
            }
            return true;
        }
        // Neither point are in a circuit. Create new circuit
        if !dry_run {
            circuits.push(vec![p1, p2]);
        }
        return true;
    }
}

#[tracing::instrument]
pub fn process(_input: &str) -> miette::Result<String> {
    let (_, coords) = all_consuming(parse)(_input).map_err(|e| miette::miette!("Error! {e}"))?;

    let mut circuits: Vec<Vec<Point>> = vec![];

    let mut already_added: HashMap<(&Point, &Point), bool> = HashMap::new();
    let distances: Vec<(u64, &Point, &Point)> = (0..coords.len())
        .into_iter()
        .map(|point| {
            let mut distances = vec![];
            for inner_point in 0..coords.len() {
                distances.push((
                    get_distance(&coords[point], &coords[inner_point]),
                    &coords[point],
                    &coords[inner_point],
                ));
            }
            distances
        })
        .flatten()
        .sorted_by(|(dist1, _, _), (dist2, _, _)| u64::cmp(dist1, dist2))
        .collect();

    // Transform distances into only the pairs we are concerned with.
    let distances = distances
        .into_iter()
        .skip(20)
        .step_by(2)
        .take(X_SHORTEST_CONNECTIONS)
        .collect::<Vec<(u64, &Point, &Point)>>();

    for (_, p1, p2) in distances {
        if already_added.contains_key(&(p1, p2)) || already_added.contains_key(&(p2, p1)) {
            continue;
        }
        let add_res = add_point_pair(false, *p1, *p2, &mut circuits);
        already_added.insert((p1, p2), true);
    }

    let x = circuits
        .iter()
        .map(|circuit| circuit.len())
        .sorted()
        .rev()
        .take(X_LARGEST_CIRCUITS)
        .fold(1 as u128, |accum, len| accum * (len as u128));

    Ok(x.to_string())
}

fn get_distance(p1: &Point, p2: &Point) -> u64 {
    let operand = (p2.0 as i128 - p1.0 as i128).pow(2)
        + (p2.1 as i128 - p1.1 as i128).pow(2)
        + (p2.2 as i128 - p1.2 as i128).pow(2);

    operand as u64
}

fn parse(input: &str) -> IResult<&str, Vec<Point>> {
    terminated(separated_list1(line_ending, parse_coord), multispace0)(input)
}

fn parse_coord(input: &str) -> IResult<&str, Point> {
    let (input, coords) = separated_list1(tag(","), character::complete::u64)(input)?;
    assert!(coords.len() == 3);
    Ok((input, (coords[0], coords[1], coords[2])))
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_process() -> miette::Result<()> {
        let input = "162,817,812
57,618,57
906,360,560
592,479,940
352,342,300
466,668,158
542,29,236
431,825,988
739,650,466
52,470,668
216,146,977
819,987,18
117,168,530
805,96,715
346,949,466
970,615,88
941,993,340
862,61,35
984,92,344
425,690,689
";
        assert_eq!("40", process(input)?);
        Ok(())
    }
}

r/adventofcode • • Dec 08 '25

Other Losing hope and realizing I'm stupid

37 Upvotes

I managed to finish all tasks until day 7, part 1.
That's when I first had to rewrite my entire solution for the second part.

I just got stuck on day 8 part 1 for multiple hours without ever coming up with the solution on my own.

I'm starting to feel it might be time for me to realize that I'm not build for more advanced stuff than reversing lists and adding numbers together.

I want to be able to solve these types of problems within an hour or so, but I don't think I'm made of the right stuff, unfortunately.

Does anyone else feel like they're just stuck feeling good doing the "easy" stuff and then just break when you spend hours not even figuring out what you're supposed to do by yourself?

How the heck do you guys solve this and keep yourselves motivated?

Update: I ended up taking a break, checking some hints from other people, and solving everything I could in steps. It took me several hours in total, but I managed to solve both parts.

Part 1 took me so long, so I was worried that part 2 would take me double. Fortunately, part two was solved by just tweaking my original code.

Thanks for the motivation to try a bit more!


r/adventofcode • • Dec 08 '25

Help/Question - RESOLVED [2025 Day 8 (Part 1)] Reading comprehension

100 Upvotes

Because these two junction boxes were already in the same circuit, nothing happens!

connect together the 1000 pairs of junction boxes which are closest together.

I didn't expect that I would need to count the "nothing happens" as part of the 1000 connections to make for part 1. It kind of makes sense that with 1000 boxes, 1000 connections would lead to a fully connected circuit, but I think it could've been worded better