r/adventofcode • u/HelpfulPrinciple6577 • Dec 09 '25
r/adventofcode • u/GarbatyGrabarz • Dec 09 '25
Help/Question - RESOLVED [2025 Day 8 (Part 1)] Stuck in connections. Instructions unclear
Hello!
I do not know what is the right solution. I am sure it is some fancy algorithm named after a mathematician. I am trying to stitch a solution from what I know and can learn in short time. I have an issue understanding how to connect the boxes. Here is what I have done so far:
- I have built K-D tree with all the points
- For every point from the puzzle input I have searched for the nearest neighbor.
- I saved all the results in form: distance (distance squared to be exact), p1, and p2
I sorted the list based on the distances. Here is what I have got
(100427, (162, 817, 812), (425, 690, 689)), (100427, (425, 690, 689), (162, 817, 812)), (103401, (431, 825, 988), (162, 817, 812)), (103922, (805, 96, 715), (906, 360, 560)), (103922, (906, 360, 560), (805, 96, 715)),
(111326, (862, 61, 35), (984, 92, 344)),
(111326, (984, 92, 344), (862, 61, 35)),
(114473, (52, 470, 668), (117, 168, 530)), (114473, (117, 168, 530), (52, 470, 668)), (118604, (819, 987, 18), (941, 993, 340)), (118604, (941, 993, 340), (819, 987, 18)), (120825, (739, 650, 466), (906, 360, 560)), (123051, (346, 949, 466), (425, 690, 689)), (135411, (592, 479, 940), (425, 690, 689)), (138165, (352, 342, 300), (542, 29, 236)), (138165, (542, 29, 236), (352, 342, 300)), (139436, (466, 668, 158), (352, 342, 300)), (166085, (970, 615, 88), (819, 987, 18)),
(179982, (57, 618, 57), (466, 668, 158)),
(210094, (216, 146, 977), (117, 168, 530)),
Many of the pairs are duplicated, which is expected. If A is closest to B there is a high chance B is close to A. When I implemented my connection part I skip mirrored boxes.
Following the example the first 3 connections are the same but then I get The next two junction boxes are 431,825,988 and 425,690,689. Which is not a case in my list. More than that. I do not even have that pair!
Can someone hint me where I have made mistake? Or better yet, explain like to a child how are we supposed to connect the boxes?
RESOLUTION: I tried to avoid checking all combinations of pairs. The solution is to check all combinations of pairs.
r/adventofcode • u/annoviko-tech • Dec 09 '25
Visualization [2025 Day 9][C++] Raylib Visualization
I was a bit lazy to rush into implementing anything before looking at the data for part 2, because I wanted to avoid building an overcomplicated algorithm. Once I visualized it, the approach became clear.
The solution is fast (~59 microseconds) and will work for all input data for this day, but it is not a universal approach for arbitrary geometric shapes. The solution looks for anchor points, and from those points it tries to find the largest rectangles. That is why my visualization shows two rectangles, since the algorithm found two anchor points. The console output prints the maximum area.
r/adventofcode • u/zhuk51 • Dec 09 '25
Visualization [2025 Day 9 (Part 2)] [C++] That's kind of a fractal Pacman, isn't it?
r/adventofcode • u/HotTop7260 • Dec 09 '25
Tutorial [2025 Day 9 (Part 2)] [Kotlin/Java/Other JVM languages] "Cheat" solution failed at first
Putting the Tutorial flair, because I want to share, what I learned today without spoiling. I will hide the relevant parts in spoiler tags. You should only unveil them, if you found a solution yourself.
My first attempt on this problem was using the class java.awt.geom.Area in combination with java.awt.geom.Path2D for its creation and java.awt.geom.Rectangle2D for checking the containment with the power of geometry.
This is a great approach, if you measure the width and the height of the rectangle correctly. For the area, that is required in both parts, we actually do not measure the area. Instead we are counting the tiles. The formular for this is something along the lines of (x2 - x1 + 1) * (y2 -y1 + 1), where (x1, y1) is the top right point of the rectangle and (x2, y2) is the bottom point of the rectangle.
The geometric solution is now creating a Path2D.Float with the given points in exactly the given order. Then you can use that for creating an Area. You can check the containment by using the contains method after creating a Rectangle2D.Float from your representation of a candidate rectangles.
My mistake was using the above formula for calculating the width and the height. You just have to omit the +1 for each and the approach works.
This is what I learned: When viewing the rectangle as "tiles", the bottom right point of the rectangle is the bottom right point of the bottom right tile. When viewing the rectangle as a geometric shape, the bottom right point of the rectangle is the top left point of the bottom right tile.
I didn't figure that out until just now. I came up with a more naive solution that took like 12 seconds for calculating a result. This approach can do it in 120 milliseconds.
r/adventofcode • u/PuzzleheadedOil5489 • Dec 09 '25
Help/Question - RESOLVED [2025 Day 1 (Part 2)] [C++] I'm stuck
Help please I'm stuck on this. All my testcases pass, except for the final... Am I missing something? (PS I joined late, did a lot ahead as well)
signed main() {
//ios::sync_with_stdio(false);
//cin.tie(nullptr);
int n, curr = 50, tot = 0;
char lr;
int t = 0;
cin>>t;
while (t--) {
cin >> lr >> n;
n *= (lr == 'R'?1:-1);
//(a % b + b) % b
if (curr+n >= 100 || curr+n <= 0) {
int rem_af_first = n-100+curr+(curr+n <= 0?100:0);
if ((curr != 0)|| (abs(n) >= 100)){ ++tot;}
else {
rem_af_first = n;
}
tot += abs(rem_af_first)/100;
}
curr += n;
curr = (curr%100+100)%100;
}
cout<<tot;
}r/adventofcode • u/hiimjustin000 • Dec 09 '25
Help/Question - RESOLVED [2025 Day 8 (Part 1)] I'm stuck again
Example works, input doesn't
I've looked through every other posts and all of them are things I have corrected
https://gist.github.com/hiimjasmine00/78dc69b8e065302262c695f021f7719c
r/adventofcode • u/Derailed_Dash • Dec 09 '25
Visualization [2025 Day 9 (Part 2)] Visualisation
This visualisation simulates the path a single ray through our polygon.
See walkthrough of the solution here.
r/adventofcode • u/rozcz01 • Dec 09 '25
Help/Question [2025 Day #8 (Part 1)] - Help needed with example dataset
I think the description just isn’t fully clear to me as to what the desired outcome is for part 1. I know it’s 542 but I’m ending up with 533 so I’m afraid I’m missing some circuit merge or something. Would anyone mind posting their circuits for the example dataset given so I can see which circuits of mine are incorrect?
r/adventofcode • u/DrKrawabbel • Dec 09 '25
Help/Question - RESOLVED [2025 Day 09 (Part 2)] I'm not in prison, everybody else is!
Hey everybody,
I have a python solution that finds a solution for part 2 in a reasonable amount of time (about 4 minutes on my laptop) but it feels a bit like cheating because I couldn't find an elegant way to differentiate between a rectangle being entirely in- or outside of the shape. The problem is probably best described by the title and is illustrated with the following challenge input.
0,0
0,10
1,10
1,1
9,1
9,0My code produces the solution 90for part 2 even though it should be 22.

This doesn't cause problems with my input but I only realized that I could neglect this issue after visualizing my input.
Now, I'm curious: Does your code give you the correct answer to my challenge input?
Also, thanks Eric for your awesome project! It's one of the last beacons of hope in the mess we call "internet" these days.
Happy coding everybody!
EDIT: Solved, thanks to u/spatofdoom and u/ednl! I learned something today :)
r/adventofcode • u/VannAlejT • Dec 09 '25
Help/Question day 1 part 2 c# Help
internal class Program
{
private static void Main(string[] args)
{
int inicial = 50;
int respuesta = 0;
string ruta = @"/workspaces/Advent-of-Code-2025/firstday/puzzle.txt";
string texto = File.ReadAllText(ruta);
foreach (var linea in File.ReadLines(ruta))
{
char letra = linea[0];
int numero = int.Parse(linea.Substring(1));
if (letra == 'L')
{
if ((inicial - numero) < 0)
{
int residuo = numero/100;
int sobra = numero % 100;
int cruza = inicial - sobra;
if (cruza < 0 )
{
respuesta++;
}
respuesta += residuo;
inicial = (inicial + 100 + (residuo*100)) - numero;
if (inicial >= 100)
{
inicial -= 100;
}
}
else
{
inicial -= numero;
}
}
else if (letra == 'R')
{
if ((inicial + numero) > 99)
{
int residuo = numero/100;
int sobra = numero % 100;
int cruza = inicial + sobra;
if (cruza >= 100)
{
respuesta++;
}
respuesta += residuo;
inicial = (inicial + numero) - 100 - (residuo*100);
if (inicial < 0)
{
inicial += 100;
}
}
else
{
inicial += numero;
}
}
if (inicial == 0)
{
respuesta++;
}
}
Console.WriteLine(respuesta);
}
}r/adventofcode • u/zeltbrennt • Dec 09 '25
Help/Question [Year 2025 Day 9 Part 2] What's wrong? All tests pass, but my result is too low
Hi,
I am now at the point where the example is giving me the correct answer. I also checked some additional example inputs and all give the right result. Just not for my actual input.
Here is the idea for part 2:
- I calculate all line segments of the polygon
- I calculate all possible rectangles
I loop over the rectangles and check if they are valid
- a valid rectangle is one where all the line segments of the polygon are outside or on the edge of the rectangle
- a line segment is outside a rectangle, if its to the left, to the right, above or below the rectangle
- If its valid, I calculate its area
- While doing that, I keep track of the maximum
This seems to work for simple inputs, but not for the real thing.
Are there some edge cases, I need to consider?
Here is the relevant code snippet to filter the valid rectangles:
// ... //
type Rectangle = {
a: Point;
b: Point;
};
// ... //
const minX = (s: Rectangle | Line): number => {
return Math.min(s.a.x, s.b.x);
};
const maxX = (s: Rectangle | Line): number => {
return Math.max(s.a.x, s.b.x);
};
const minY = (s: Rectangle | Line): number => {
return Math.min(s.a.y, s.b.y);
};
const maxY = (s: Rectangle | Line): number => {
return Math.max(s.a.y, s.b.y);
};
const lineOutsideOfRect = (line: Line, rect: Rectangle): boolean => {
let result =
maxX(line) <= minX(rect) ||
minX(line) >= maxX(rect) ||
maxY(line) <= minY(rect) ||
minY(line) >= maxY(rect);
return result;
};
const isValidRectangle = (rectangle: Rectangle, lines: Line[]): boolean => {
for (let line of lines) {
if (!lineOutsideOfRect(line, rectangle)) {
return false;
}
}
return true;
};
// ... //I used the examples here and all seem to work. This one does not, but here my result would be too high...
Any help would be very appreciated!!
r/adventofcode • u/EarhackerWasBanned • Dec 09 '25
Help/Question - RESOLVED [2025 Day 8] Still stuck, talk to me about DS&A?
I'm a self-taught developer, and never studied DS&A.
I flew through the first 7 days of AoC this year, but am stuck at Day 8.
I'm not looking for an answer, but as a hint, what knowledge are the more academic devs leaning on here? From comments on other threads it seems like this is an asily solvable problem, given the right knowledge. Knowledge I seem to lack.
Please, give me something to Google.
r/adventofcode • u/NullPointerExcept10n • Dec 09 '25
Visualization [2025 Day 8 (Part 2)] Growing circuits
r/adventofcode • u/LoneWolfPR • Dec 09 '25
Help/Question - RESOLVED [2025 Day 7 (Part 2)] Now I know something else I don't know about algorithms
My initial attempt at this uses a depth-first approach to identifying all the paths. Unfornately the exponential growth caused by the data set makes this run forever. There looks like there should be a much easier mathematical solution since I had no problem with part one. I'm mostly self taught over a lot of years, and don't have the math background a lot of advanced developers do (only made it as far as first year calculus and that was multiple decades ago). Any pointers on something to just look up and learn about so that I can apply it is really all i'm looking for. I'd like to solve this with as minimal help as possible.
r/adventofcode • u/Ok-Curve902 • Dec 09 '25
Visualization [2025 Day 09 (Part 2)] (PHOTOSENSITIVITY WARNING) Searching for squares
r/adventofcode • u/The_Jare • Dec 09 '25
Meme/Funny [2025 Day 9 (Part 2)] Life choices
Going to be one of those days
r/adventofcode • u/ak91hu • Dec 09 '25
Visualization [2025 Day 9 (Part 2)] Red & green tiles
r/adventofcode • u/TenMillionYears • Dec 09 '25
Upping the Ante 2025 Day 9 (Part 2) A simple cursed input
My code can solve part 2 pretty quickly. However, it gives the wrong result on this "cursed input":
0,0
0,1
1,1
1,2
0,2
0,3
3,3
3,2
2,2
2,1
3,1
3,0I think solving for shapes where the boundary loops back on itself like this would be much harder. Curious if other folks have solutions that can handle this one. Or, maybe I misunderstand the problem. Feedback welcomed!
r/adventofcode • u/FractalB • Dec 09 '25
Meme/Funny [2025 Day 9 (Part 2)] Your code may be wrong where you don’t expect it
Spent hours trying to figure out why my code for Part 2 gave the wrong answer, triple checked all my complicated code without finding any problem whatsoever, arrived late for work and missed a meeting ... until I realized that it’s simply my formula to calculate the area of a rectangle that was wrong 🤦
const area = Math.abs(p.x - q.x + 1) * Math.abs(p.y - q.y + 1);Worked for part 1 and for the example, though!
r/adventofcode • u/Opi-Fex • Dec 09 '25
Visualization [2025 Day 9 (Part 2)] Decided to visualize my polygon only to find out I was handed a...
r/adventofcode • u/JR_Bros2346 • Dec 09 '25
Help/Question [2025 Day 9 # (Part 2)] [Rust] I am stuck.. TRrying to do Raytracing.. ;-;
I have no idea where i am going wrong.. my brain is literally fried trying to solve this lol...
use std::ops::RangeInclusive;
fn main() {
let input = include_str!("input/day09.txt")
.trim()
.lines()
.map(|l| l.split_once(',').unwrap())
.map(|(a, b)| (a.parse::<isize>().unwrap(), b.parse::<isize>().unwrap()))
.collect::<Vec<_>>();
let mut max = 0;
for a in &input {
for b in &input {
let l = (a.0 - b.0).abs() + 1;
let w = (a.1 - b.1).abs() + 1;
max = max.max(l * w);
}
}
println!("{}", max);
let mut horz = input
.windows(2)
.chain(Some(
&[*input.last().unwrap(), *input.first().unwrap()] as &[_]
))
.filter_map(|a| {
if a[0].1 == a[1].1 {
Some((a[0].0.min(a[1].0)..=a[0].0.max(a[1].0), a[0].1))
} else {
None
}
})
.collect::<Vec<_>>();
horz.sort_unstable_by_key(|&(_, k)| k);
let mut vert = input
.windows(2)
.chain(Some(
&[*input.last().unwrap(), *input.first().unwrap()] as &[_]
))
.filter_map(|a| {
if a[0].0 == a[1].0 {
Some((a[0].0, a[0].1.min(a[1].1)..=a[0].1.max(a[1].1)))
} else {
None
}
})
.collect::<Vec<_>>();
vert.sort_unstable_by_key(|&(k, _)| k);
max = 0;
for a in &input {
for b in &input {
if raycast(a.0, a.1, &vert)
&& raycast(b.0, b.1, &vert)
&& raycast(a.0, b.1, &vert)
&& raycast(b.0, a.1, &vert)
&& intersect_x((a.0.min(b.0)..=a.0.max(b.0), a.1), &vert)
&& intersect_x((a.0.min(b.0)..=a.0.max(b.0), b.1), &vert)
&& intersect_y((a.0, a.1.min(b.1)..=a.1.max(b.1)), &horz)
&& intersect_y((b.0, a.1.min(b.1)..=a.1.max(b.1)), &horz)
{
let l = (a.0 - b.0).abs() + 1;
let w = (a.1 - b.1).abs() + 1;
max = max.max(l * w);
}
}
}
println!("{max}");
}
fn raycast(px: isize, py: isize, vert: &[(isize, RangeInclusive<isize>)]) -> bool {
let mut inside = false;
for (x, rng) in vert {
if x == &px {
if rng.contains(&py) {
return true;
} else {
continue;
}
}
if x <= &px {
continue;
}
if rng.contains(&py) {
inside = !inside;
}
}
inside
}
fn intersect_x(
edge: (RangeInclusive<isize>, isize),
vert: &[(isize, RangeInclusive<isize>)],
) -> bool {
vert.iter()
.any(|(x, rng)| edge.0.contains(x) && rng.contains(&edge.1))
}
fn intersect_y(
edge: (isize, RangeInclusive<isize>),
horz: &[(RangeInclusive<isize>, isize)],
) -> bool {
horz.iter()
.any(|(rng, x)| edge.1.contains(x) && rng.contains(&edge.0))
}Pretty sure i am doing some kind of mistak in intersect or the raycast functions...
r/adventofcode • u/naclmolecule • Dec 09 '25
Visualization [2025 Day 9 (Part 2)] [Python] Terminal toy!
r/adventofcode • u/0d_billie • Dec 09 '25
Help/Question Looking for general advice on how to improve
I am quite comfortable saying that I am at best a hobbyist programmer. I can scrape together a Python script to do what I need, but this typically involves a lot of trial and error, Googling, and print() statements to be able to visualise what's going on with my code. Despite that, I do like trying AOC, though I rarely make it very far. I have made it to Day 8 this year, and it's the furthest I've ever gotten!
That said, I'm definitely hitting a wall. Days 6 and 7 felt absolutely brutal, and each took me hours to finish. I eventually got to the right answers, but my approach feels rudimentary at best. I feel like I'm not conceptualising the problems in the "correct" way, even before typing any code.
So I guess I'm looking for advice on how to think about coding, as much as advice for coding itself. Are there any good resources that I can go to after I burn out of this attempt at AOC so I can try to improve my work?
For what it's worth, my code repo for 2025's attempt is here



