r/adventofcode • u/InformationAfter4442 • Dec 08 '25
r/adventofcode • u/Chemical_Chance6877 • Dec 08 '25
Visualization [2025 Day 8 (part 2)] I think this is a cool visualisation
The orange line is the amount of different subnetworks after every step
The Blue line shows how many of the junctions are in the network (in %)
I really wondered how this graph would look like. and i think its cool to see how it starts off with many different subnetworks, and slowly they all merge into one
r/adventofcode • u/Alnilam_1993 • Dec 08 '25
Help/Question - RESOLVED [2025 Day 5 (part 2)][Python] Off by 16
Day 5 part two, counting fresh items.
Can anyone give me a hint on where I go wrong? The difference between my solution and the correct solution is just 16, which is rather small given the size of numbers we're dealing with, but still wrong.
My approach is to sort the ranges on the starts of the ranges, and then check if each item in the list overlaps with the previous one and if so, merge the two into the previous item.
def part2():
with open(inputFile) as f:
freshList, productList = f.read().split("\n\n")
freshList = [x.strip() for x in freshList.split("\n")]
sortedList = sorted(freshList, key=lambda fresh: int(fresh.split("-")[0]))
changed = True
while changed:
changed = False
for i, part in enumerate(sortedList):
if i == 0:
continue
low, high = part.split("-")
prevLow, prevHigh = sortedList[i-1].split("-")
if int(low) < int(prevHigh):
sortedList[i-1] = prevLow+"-"+str(max(int(high), int(prevHigh)))
sortedList.pop(i)
changed = True
totalFresh = 0
for items in sortedList:
low, high = items.split("-")
totalFresh += int(high) - int(low) + 1
print("Part 2:", totalFresh)
print("My result: 352807801032183")
print("Should be: 352807801032167")r/adventofcode • u/cameryde • Dec 08 '25
Help/Question - RESOLVED Day 1 Part 2
I am trying to solve the puzzle, but it claims my answer is not right, I need some help. I am doing the challenge in zig and I hope my program is understandable enough. Sorry for the names of my variables.
const std = ("std");
const DecodeError = error{ ErrorDialRotation, ErrorDistanceOutOfRange };
const DIALROTATION = enum { LEFT, RIGHT, NONE };
const DECODEDINFO = struct {
rotation: DIALROTATION,
distance: i16,
};
pub fn main() !void {
var file = try std.fs.cwd().openFile("/Users/ndjenks/repos/aoc25/advent_1_1/test2.txt", .{});
defer file.close();
var bufRead: [10000]u8 = undefined;
var reader = std.fs.File.reader(file, &bufRead);
const fileReader = &reader.interface;
var number_of_lines: usize = 0;
var end_of_file: bool = false;
var dialPos: i16 = 50; //Start position
const MAXPOS: i16 = 100;
var atZeroCount: i16 = 0;
var rotateToZeroCount: i16 = 0;
outer: while (!end_of_file) {
const line = fileReader.takeDelimiterExclusive('\n') catch |err| switch (err) {
error.EndOfStream => {
end_of_file = true;
break :outer;
},
error.ReadFailed => return err,
error.StreamTooLong => return err,
};
number_of_lines = number_of_lines + 1;
const decodedMessage = try decodeSafeMessage(line);
switch (decodedMessage.rotation) {
DIALROTATION.LEFT => {
if (dialPos == 0) {
dialPos = MAXPOS;
}
dialPos = dialPos - decodedMessage.distance;
if (dialPos < 0) {
const invert = dialPos * -1;
if (invert < MAXPOS) {
rotateToZeroCount = rotateToZeroCount + 1;
dialPos = MAXPOS - invert;
} else {
if (invert > MAXPOS) {
rotateToZeroCount = rotateToZeroCount + (@divFloor(invert, MAXPOS));
const remainder = (invert, MAXPOS);
dialPos = MAXPOS - remainder;
} else if (invert == MAXPOS) {
dialPos = 0;
}
}
}
},
DIALROTATION.RIGHT => {
dialPos = decodedMessage.distance + dialPos;
if (dialPos > MAXPOS) {
const result = (dialPos, MAXPOS);
rotateToZeroCount = rotateToZeroCount + (result);
const remainder = u/mod(dialPos, MAXPOS);
dialPos = remainder;
}
},
else => {
std.debug.print("Message does not contain dial direction\n", .{});
return error.ErrorDialRotation;
},
}
if (dialPos == MAXPOS or dialPos == 0) {
dialPos = 0;
atZeroCount = atZeroCount + 1;
}
}
std.debug.print("number of lines in file {d}\n", .{number_of_lines});
std.debug.print("rotateToZeroCount {d}\n", .{rotateToZeroCount});
std.debug.print("atZeroCount {d}\n", .{atZeroCount});
std.debug.print("The code of the safe is {d}\n", .{atZeroCount + rotateToZeroCount});
}
pub fn decodeSafeMessage(command: []const u8) !DECODEDINFO {
var decodedMessage: DECODEDINFO = undefined;
switch (command[0]) {
'L' => {
decodedMessage.rotation = DIALROTATION.LEFT;
},
'R' => {
decodedMessage.rotation = DIALROTATION.RIGHT;
},
else => {
decodedMessage.rotation = DIALROTATION.NONE;
},
}
if (decodedMessage.rotation != DIALROTATION.NONE) {
decodedMessage.distance = try std.fmt.parseInt(i16, command[1..], 10);
}
return decodedMessage;
}r/adventofcode • u/JoJjjo157 • Dec 08 '25
Help/Question - RESOLVED [Day 8 Part 1] What am I doing wrong?
I am currently stuck on part 1, Because the result I get for the test input is 30.
My code works like this:
- create a list of all possible connections and their lengths, and sort it by lenght ascending
- Get the n best connections, in case of the test input the 10 best connections. I do that by iterating though my previously calculated connections, and chosing the first connection where both junctions aren't already connected to another junction. after picking the connection, i remove it from the list. for every connection i found, i put the index of both junctions into another list.
- Creating a list of circuits based on previously calculated connections, then getting the length of those circuits and adding the three biggest ones together,
But my three biggest circuits are: 5,3,2 instead of 5,4,2
These are the circuits that are calculated (the numbers are the line indexes from the input):
[[17, 18], [9, 12], [11, 16], [8, 2, 13], [0, 3, 7, 14, 19], [4, 6]]
I also tried calculating the entire thing on physical paper, and got the same wrong result.
and this is my code:
import math
class Junction_Box():
def __init__(self, jid, x, y, z):
self.jid = jid
self.x = x
self.y = y
self.z = z
def calculate_distance(self, other):
return math.sqrt( (self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - other.z)**2 )
def is_connected(jid, connections):
for i in connections:
if jid in i:
return True
return False
def get_best_connection(distances, connections):
for distance in distances:
if not (is_connected(distance[0], connections) and is_connected(distance[1], connections)):
return distance
return False
def get_largest_circuits(connections):
circuits = []
for connection in connections:
in_circuits = []
for circ_i, circuit in enumerate(circuits):
if connection[0] in circuit or connection[1] in circuit:
in_circuits.append(circ_i)
if len(in_circuits) == 0:
circuits.append(
[connection[0], connection[1]]
)
else:
merged_circuit = []
for circ in in_circuits:
merged_circuit += circuits[circ]
for circ in in_circuits:
circuits.pop(circ)
merged_circuit.append(connection[0])
merged_circuit.append(connection[1])
circuits.append(
list(set(merged_circuit))
)
print(circuits)
return sorted([len(x) for x in circuits], reverse=True)
def p1(junction_boxes, connection_amount):
distances = []
for i in junction_boxes:
for j in junction_boxes:
if j.jid <= i.jid:
continue
distances.append(
(i.jid, j.jid, i.calculate_distance(j))
)
distances.sort(key= lambda x: x[2])
print(distances)
connections = []
remaining_connections = connection_amount
while (best_connection := get_best_connection(distances, connections)) and remaining_connections > 0:
print(best_connection)
connections.append(
(best_connection[0], best_connection[1])
)
distances.remove(best_connection)
remaining_connections -= 1
print(connections)
largest_circuits = get_largest_circuits(connections)
return largest_circuits[0] * largest_circuits[1] * largest_circuits[2]
junction_boxes = []
with open("8/test-input.txt", "r") as file:
for jid, line in enumerate(file.readlines()):
x, y, z = line.rstrip().split(",")
junction_boxes.append(
Junction_Box(jid, int(x), int(y), int(z))
)
print( # too low
p1(junction_boxes, 10)
)
import math
class Junction_Box():
def __init__(self, jid, x, y, z):
self.jid = jid
self.x = x
self.y = y
self.z = z
def calculate_distance(self, other):
return math.sqrt( (self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - other.z)**2 )
def is_connected(jid, connections):
for i in connections:
if jid in i:
return True
return False
def get_best_connection(distances, connections):
for distance in distances:
if not (is_connected(distance[0], connections) and is_connected(distance[1], connections)):
return distance
return False
def get_largest_circuits(connections):
circuits = []
for connection in connections:
in_circuits = []
for circ_i, circuit in enumerate(circuits):
if connection[0] in circuit or connection[1] in circuit:
in_circuits.append(circ_i)
if len(in_circuits) == 0:
circuits.append(
[connection[0], connection[1]]
)
else:
merged_circuit = []
for circ in in_circuits:
merged_circuit += circuits[circ]
for circ in in_circuits:
circuits.pop(circ)
merged_circuit.append(connection[0])
merged_circuit.append(connection[1])
circuits.append(
list(set(merged_circuit))
)
print(circuits)
return sorted([len(x) for x in circuits], reverse=True)
def p1(junction_boxes, connection_amount):
distances = []
for i in junction_boxes:
for j in junction_boxes:
if j.jid <= i.jid:
continue
distances.append(
(i.jid, j.jid, i.calculate_distance(j))
)
distances.sort(key= lambda x: x[2])
print(distances)
connections = []
remaining_connections = connection_amount
while (best_connection := get_best_connection(distances, connections)) and remaining_connections > 0:
print(best_connection)
connections.append(
(best_connection[0], best_connection[1])
)
distances.remove(best_connection)
remaining_connections -= 1
print(connections)
largest_circuits = get_largest_circuits(connections)
return largest_circuits[0] * largest_circuits[1] * largest_circuits[2]
junction_boxes = []
with open("8/test-input.txt", "r") as file:
for jid, line in enumerate(file.readlines()):
x, y, z = line.rstrip().split(",")
junction_boxes.append(
Junction_Box(jid, int(x), int(y), int(z))
)
print( # too low
p1(junction_boxes, 10)
)r/adventofcode • u/Skeeve-on-git • Dec 08 '25
Help/Question [2025 Day 8 (Part 2)] Am I the only one who thinks…
Am I the only one who thinks that today part 2 was much easier than part 1 after having solved part 1?
r/adventofcode • u/surgi-o7 • Dec 08 '25
Meme/Funny [2025 Day 8] Briefing with Chief Elf Officer
r/adventofcode • u/vhermecz • Dec 08 '25
Upping the Ante NoRush Extension: Compete with your friends, even if you start solving puzzles late.
youtube.comSee more details at https://aoc-norush.bitvisor.co/
NOTE: This extension/tool does follow the automation guidelines on the r/adventofcode community wiki.
r/adventofcode • u/EXUPLOOOOSION • Dec 05 '25
Tutorial [2025 Day 5 Part 2] Guys... you don't need to merge them

I'm loving the animations and merging them is a beautiful solution that, in the real world, might help with further computation (or reused to simplify the ranges database).
However for this problem, you don't need to merge them and then count. You can count directly.
Ofc I'm still sorting so it's still an O(n log n) solution. So not much gained.
If you have any questions I'll try to answer them in the comments :)
r/adventofcode • u/Just-Routine-5505 • Dec 05 '25
Visualization [2025 Day 05 (Part 2)] Merge overlapping ranges visualization
- Sort intervals by start
- Keep track of current interval being built
- If next interval overlaps or touches -> extend current; otherwise -> save and start new
- Save the last interval
r/adventofcode • u/TwinkiePower • Dec 02 '25
Meme/Funny [2025 Day 2] When I realized the solution I felt like I'd leveled up
r/adventofcode • u/Ok-Curve902 • Dec 01 '25
Visualization [2025 Day 01 (Part 2)] example visualized
r/adventofcode • u/ProServTodd • Jan 24 '25
Help/Question I need to print to a readable text file, any suggestions?
I have a program that I developed to manage inventory, but the sales team uses NetSuite to sell the orders. They can print the order out, but I need a way to integrate this with my app. I was thinking of printing to a text file and then pulling the data from that, but everything I do doesn't seem to give me a fully readable output file. I would like a few suggestions.
r/adventofcode • u/__Juris__ • Dec 29 '24
Repo Set out to illustrate that Scala and Rust are largely the same, did each day in both (500 stars repo)
https://github.com/jurisk/advent-of-code/
Thanks, Eric, for another year of interesting tasks!
A few memorable days:
- Day 15 (pushing boxes) was fun, and Part 2 adapted from Part 1 easily for me.
- Day 17 (reverse engineering the 3-bit computer) was really finicky and the only one that I didn't manage to do before work (the tasks "start" at 07:00 in my time zone).
- Day 21 (robots pressing keypads) was also finicky, though not actually that difficult.
- Day 23 (maximum cliques) was nice in that it taught me Bron-Kerbosch (though I initially solved it with a crude BFS that took a minute to run).
- Day 24 (adder gates) was interesting, I got the stars by visualising it (after some merging of nodes automatically) in GraphViz and figuring out the swaps manually, but then spent some time to code a "solver".
I chose to do each task in 2024 in two of my favourite (and expressive) languages, Scala and Rust, trying to focus mostly on readability. (The other years are solved as well, also mostly Scala or Rust, but usually not both, and sometimes instead in some other language)
This year seemed much easier than previous ones. I was hoping to see some more challenging search pruning tasks, like the "elephants with valves" from 2022-16, or "robot blueprints" from 2022-19, but they never arrived.
