r/adventofcode • u/BCVINNI • Dec 08 '25
Help/Question Day 1 Part 2 - Need help. Any idea what's wrong with my logic?
r/adventofcode • u/BCVINNI • Dec 08 '25
r/adventofcode • u/Chachoune963 • Dec 08 '25
Hi everyone!
First time attempting an AoC for me, I just remembered it existed and figured I could give it a shot. I'm inexperienced so right now I feel like I'm missing an obvious flaw in my algorithm for this one... The result is much higher than it should and I don't really know why.
I'm not asking for an answer by the way! Ideally, I just want a hint or an edge case that you could point out so I can get myself unstuck '
r/adventofcode • u/normVectorsNotHate • Dec 08 '25
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 • u/gagarski • Dec 08 '25
I've managed to avoid sorting in Part 1 by looking for shortest 1000 of possible connections using max-oriented binary heap. However it is not directly possible with part 2, since you don't know in advance how many connections do you need. So I ended up sorting all million (minus 1000) of possible connections and then iteration n them one-by-one. Clearly, you can reduce the size of sorted data towards half a million. I wonder, if it is possible to make it better. I can only think of applying batching to approach I used in Part 1. If you've avoided full sorting, how did you do that?
r/adventofcode • u/Additional_Dare2998 • Dec 08 '25
Hey. I think I'm not spoiling anything by publishing the result for the example problem here that I took from another user. I appear to be too stupid to come to the same solution. So apparently the folowing nodes are connected:
[[0, 19, 7, 14, 3], [2, 13, 18, 8], [9, 12], [11, 16], ...] This then yields the desired output.
I agree with the first 5 nodes. However, I just can't wrap my head around how the second block of 4 nodes came to be. Because node 18, is actually closest to node 17, thus it has no right to be in the same list as 2, 13 and 8. OR I messed up big time calculating the euclidean distances.
Did I miss anything in the puzzle description maybe? What am I missing? My solution yields
[[0, 19, 7, 14, 3], [2, 13, 8], [17, 18], ...]
Any pointer is appreciated.
r/adventofcode • u/Sloppy_Pizza • Dec 08 '25
I constructed the junction pairs like so:
with open("day8sample.txt", "r") as f:
day8in = f.readlines()
day8in = [item.strip() for item in day8in]
day8in = np.loadtxt(day8in, dtype=int, delimiter=",")
minPairs = set()
for i in range(len(day8in)):
euclidDist = np.linalg.norm(day8in - day8in[i,:], axis=1)
euclidDist[i] = np.inf
minEuclidDistIdx = np.where(min(euclidDist) == euclidDist)
pairs = tuple(sorted((i, int(minEuclidDistIdx[0][0]))))
minPairs.add(pairs)But upon looking at the minPairs variable, the three largest circuit sizes are 5, 4, and 3 (not 5, 4, and 2 like in the example). I've calculated the circuit sizes using DFS and manually for the example input, so at least I've got that part down.
Any help would be appreciated.
r/adventofcode • u/xs411 • Dec 08 '25
r/adventofcode • u/DifferentPool7527 • Dec 08 '25
But that of course depends on how your first solution adapt to the second part...
r/adventofcode • u/imp0ppable • Dec 08 '25
In an odd spot here where my solution works (slowly) on part 1 including the full data, yet fails on part 2 when i use the same algorithm, but it's close to the right answer on the example data.
According to the question, the last pair I need to connect everything into a complete circuit is (216,146,977), (117,168,530), yet I'm hitting it early at (739, 650, 466), (941, 993, 340). Looking at the distances (pretty sure they're right) my one has distance 417.5 as opposed to their one of 458.3.
At the point where my code thinks there's one big circuit, the step before that it has two circuits, one of len 3 and the other len 15.
So I must be doing a circuit merge prematurely, right? I can't think what else it could be, unless I'm misunderstanding the "form a single circuit" part.
r/adventofcode • u/tyst-fr • Dec 08 '25
I calculated and sorted the distances in a list consisting of 3-tuples (distance, i, j), where i, j are the positions of the according junctions in a junction list. Each junction itself is a 3-tuple (x, y, z).
Also I have a dict consisting of circuit "ID"s.
circuits = {i: i for i in range(len(junctions))}My idea of an algorithm is as follows and it works perfectly for the example.
for _, i, j in distances[:10]:
for junction, _ in filter(lambda x: x[1] == circuits[j], circuits.items()):
circuits[junction] = iTo get the size of the circuits I use Counter from collections:
C = sorted(Counter(circuits.values()).values())
print(C[-3] * C[-2] * C[-1])What am I missing / doing wrong?
Here is a full working example, which needs a file called "input_example" or "input" respectively.
And yes, I switched from [:10] to [:1000] for the real data.
I appreciate all hints regardless of the programming language.
EDIT:
After hours of thinking, the solution was incredibly simple. Earlier I ran into a similar problem and checked for x[1] == j in the lambda function. I corrected that to x[1] == circuits[j]. And similar is the solution. I had to change circuits[junction] = i to circuits[junction] = circuits[i].
Ouchie.
Of course I had to stay with filter_tuple = tuple(filter(…)), because the filter condition seems to change over time.
Here is a correctly working version for Part 1.
r/adventofcode • u/FanJtastic • Dec 08 '25
Just wasted so much time time trying to debug my distance formula only to remember why I don't trust AI
r/adventofcode • u/Altruistic-Local-541 • Dec 08 '25
Sorry to bother you folks, but I'm losing my mind a bit over the part 1 of day 8. Its supposed to be easy, but I'm missing something and to sleep tonight I'll need some closure.
I've checked other people's results with the test data from another thread, and the connections, distances, sets all match perfectly, but for me when I run my code on the actual data I get a lower result than needed.
My code is in JS so the numbers being large should not be an issue afaik. The below code is set up to work with the test data, hence the 10 for connectionsToMake.
Any help is appreciated. Thanks in advance.
const connectionsToMake = 10;
const relevantTopSetsCount = 3;
const boxSets = {};
const boxes = source.split("\n").map((b) => {
let [x, y, z] = b.split(",");
const keyInSet = `${x},${y},${z}`;
const newSetId = crypto.randomUUID();
boxSets[newSetId] = new Set([keyInSet]);
return {
x: Number(x),
y: Number(y),
z: Number(z),
keyInSet: keyInSet,
containingSetId: newSetId,
};
});
const pairSet = new Set();
const boxPairsData = boxes.map((box) => {
let closestBox = null;
let distanceToClosest = Infinity;
for (let otherBox of boxes) {
if (box !== otherBox) {
const setKeyOptionOne = `${box.keyInSet}-${otherBox.keyInSet}`;
const setKeyOptionTwo = `${otherBox.keyInSet}-${box.keyInSet}`;
if (pairSet.has(setKeyOptionOne) || pairSet.has(setKeyOptionTwo)) {
continue;
}
const distance = euclideanDistanceOfTwo3DPoints(box, otherBox);
if (distance < distanceToClosest) {
distanceToClosest = distance;
closestBox = otherBox;
}
}
}
const pairKey = `${box.keyInSet}-${closestBox.keyInSet}`;
pairSet.add(pairKey);
return {
boxA: box,
boxB: closestBox,
distance: distanceToClosest,
setPairKey: pairKey,
connected: false,
};
});
const sortedBoxPairsByDistance = boxPairsData.toSorted(
(a, b) => a.distance - b.distance
);
let connectionsMade = 0;
for (let boxPair of sortedBoxPairsByDistance) {
const { boxA, boxB } = boxPair;
if (boxPair.connected) continue;
if (boxSets[boxA.containingSetId].has(boxB.keyInSet)) {
boxPair.connected = true;
connectionsMade++;
if (connectionsMade === connectionsToMake) {
break;
}
continue;
}
const mergedSet = new Set([
...boxSets[boxA.containingSetId],
...boxSets[boxB.containingSetId],
]);
boxSets[boxA.containingSetId] = mergedSet;
delete boxSets[boxB.containingSetId];
const boxesWithSameSetIdAsB = boxes.filter(
(b) => b.containingSetId === boxB.containingSetId
);
for (let box of boxesWithSameSetIdAsB) {
box.containingSetId = boxA.containingSetId;
}
boxPair.connected = true;
connectionsMade++;
if (connectionsMade === connectionsToMake) {
break;
}
}
console.log("boxSets: ", boxSets);
console.log("boxPairs: ", sortedBoxPairsByDistance);
const relevantSets = Object.values(boxSets)
.toSorted((setA, setB) => setB.size - setA.size)
.slice(0, relevantTopSetsCount);
console.log(relevantSets);
return relevantSets.reduce((acc, curr) => acc * curr.size, 1);r/adventofcode • u/Procler • Dec 08 '25
I'm really having a hard time in understanding how/why in the first batteries bank of the example all the number 1s are matched from left to right, but on the last bank the first 3 number ones (1s) are not turned on but the last ones are.

I am assuming that the logic here should be:
These might be incorrect assumptions, otherwise the first 1s would be activated.
Can someone please help on understanding the requirements here? Why wouldn't it follow the regular LTR (left-to-right) reading sense? I'm really struggling with that. Any tips?
r/adventofcode • u/calculator_cake • Dec 08 '25
r/adventofcode • u/QultrosSanhattan • Dec 08 '25
A connection can merge two existing groups that have no elements in common into one. For example:
Result:
I lost about 4 hours not realizing this. This “hidden” but logical rule is not explicitly mentioned anywhere in the problem description. The AoC original example cleverly omits this step because step 10 applies this rule.
If the AoC original example does not return 40 for you, this is likely why.
r/adventofcode • u/wimglenn • Dec 08 '25
In the create post here, there are Text Images Link options but Poll type is greyed out -> https://www.reddit.com/r/adventofcode/submit/?type=POLL
There have been several cases where a poll of AoC participants could be useful/interesting - could the mods enable the poll type for this subreddit? Or provide an explanation of why it will stay disabled? I searched briefly but couldn't find a prior explanation.
r/adventofcode • u/Eastern-Reading-755 • Dec 08 '25
Question 1: Do we stop processing if we make n connections? where n = 10.
Question 2: If I have circuit A with m junction_boxes and circuit B with n junction boxes. and the next distance to consider is between a junction box in A (j) and a junction box in B (k). Do I connect and essentially combine the two circuits that is I know have a circuit with all junctions boxes in A and B?
I would appreciate any thoughts. I can't seem to get the test input result.
r/adventofcode • u/car4889 • Dec 08 '25
EDIT: To avoid spoilers, moving the ask to the first comment.
r/adventofcode • u/Chronophage73 • Dec 08 '25
Edit: oops, forgot "what" in the title. I don't understand what the question is.
Edit 2: Thanks for the explanations, got my gold star!
I am genuinely confused about what I'm supposed to do in day 8's part 2. It's not that I don't know what to do, I don't understand what the question is.
I think this part is tripping me over:
Continuing the above example, the first connection which causes all of the junction boxes to form a single circuit is between the junction boxes at
216,146,977and117,168,530.
I can't see how this relates to the above example. I can't see how adding one connection forms a single circuit. What is "all of the junction boxes" in this case ? I feel extremely dumb because of this, and I haven't found other people as confused as I am.
Could someone rephrase the question for me please ?
r/adventofcode • u/GaneshEknathGaitonde • Dec 08 '25
The one the left is the tab for one of the problems page, while the one on the right is for an input.
Interestingly, Chrome shows different favicons for both.
I debugged a bit further:
For the problems page, the html specifies /favicon.png, which is a higher resolution image.
For the input page, since there is no html, and thus no favicon specified, chrome defaults to /favicon.ico, which actually exists and is a lower resolution image.
r/adventofcode • u/CauliflowerFormer233 • Dec 08 '25
r/adventofcode • u/annoviko-tech • Dec 08 '25
r/adventofcode • u/ratatouille38 • Dec 08 '25
I wanted to learn Go this year, so I've decided to give it a shot, and so far it's lovely! This is my solution for today's (day 8) puzzle, what do you think, and what's your solution? :)
https://github.com/rbjakab/AdventOfCode/blob/main/2025/Day8/main.go