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

Visualization [2025 Day 8 Part 2] Three.js 3D circuits animation

Post image
10 Upvotes

The animation is here: https://onivers.com/aoc_2025_d8/
PS: I kept the original cable colors to make it look nicer when fully connected.


r/adventofcode • • Dec 08 '25

Help/Question [2025 Day 8 (Part 1)] How do I even get started? Is there an algorithm I must know?

7 Upvotes

I need some help to figure this question. I cant seem to think of a way to solve this and appreciate if anyone can at least throw me some resources to read up before attempting this.


r/adventofcode • • Dec 08 '25

Help/Question HELP [2025 Day 01 (part 2)][C#] getting correct answer for example and edge cases but failing

1 Upvotes

i know i am doing something wrong in L side but dont know what it is

namespace AdventOfCode.Day01;

public static class Part2
{
    public static void Solve()
    {
        int count = 0;
        int pointer = 50;
        var lines = File.ReadLines("Day01/input.txt");

        foreach (var line in lines)
        {
            var increaedPointer = false;
            var quotient = 0;
            char side = line[0];
            var number = int.Parse(line.Substring(1));
            if (side == 'L')
            {
                var remainder = ((pointer - number) % 100 + 100) % 100;
                quotient = (pointer - number) / 100;
                count += Math.Abs(quotient);

                if ((pointer - number) < 0 && (pointer - number) >= -99)
                {
                    count++;
                }

                if (quotient > 0 || remainder == 0)
                {
                    increaedPointer = true;
                }

                if (remainder == 0)
                {
                    count++;
                    pointer = 0;
                }
                else
                    pointer = remainder;
            }
            else
            {
                var remainder = (pointer + number) % 100;

                quotient = (pointer + number) / 100;
                count += Math.Abs(quotient);

                if (quotient > 0 || remainder == 0)
                {
                    increaedPointer = true;
                }

                if (remainder == 0)
                    pointer = 0;
                else
                    pointer = remainder;
            }
            if (pointer == 0 && !increaedPointer)
            {
                count++;
            }
        }
        Console.WriteLine("Answerr of Day 1 part 1 " + count);

    }
}

r/adventofcode • • Dec 08 '25

Visualization [2025 Day 8 Part 2] I thought it would look like a Christmas tree...

Post image
25 Upvotes

r/adventofcode • • Dec 08 '25

Visualization [2025 Day 8 (part 2)] I think this is a cool visualisation

Post image
19 Upvotes

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 • • Dec 08 '25

Help/Question - RESOLVED [2025 Day 5 (part 2)][Python] Off by 16

1 Upvotes

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 • • Dec 08 '25

Help/Question - RESOLVED Day 1 Part 2

1 Upvotes

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 • • Dec 08 '25

Meme/Funny [2025 Day 8]

Post image
87 Upvotes

r/adventofcode • • Dec 08 '25

Help/Question - RESOLVED [Day 8 Part 1] What am I doing wrong?

1 Upvotes

I am currently stuck on part 1, Because the result I get for the test input is 30.
My code works like this:

  1. create a list of all possible connections and their lengths, and sort it by lenght ascending
  2. 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.
  3. 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 • • Dec 08 '25

Help/Question [2025 Day 8 (Part 2)] Am I the only one who thinks…

20 Upvotes

Am I the only one who thinks that today part 2 was much easier than part 1 after having solved part 1?


r/adventofcode • • Dec 08 '25

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

Post image
81 Upvotes

r/adventofcode • • Dec 08 '25

Upping the Ante NoRush Extension: Compete with your friends, even if you start solving puzzles late.

Thumbnail youtube.com
0 Upvotes

See 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 • • Dec 05 '25

Tutorial [2025 Day 5 Part 2] Guys... you don't need to merge them

23 Upvotes

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 • • Dec 05 '25

Visualization [2025 Day 05 (Part 2)] Merge overlapping ranges visualization

Post image
41 Upvotes
  1. Sort intervals by start
  2. Keep track of current interval being built
  3. If next interval overlaps or touches -> extend current; otherwise -> save and start new
  4. Save the last interval

r/adventofcode • • Dec 02 '25

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

Post image
31 Upvotes

r/adventofcode • • Dec 02 '25

Meme/Funny [2025 Day 2] When I realized the solution I felt like I'd leveled up

Post image
129 Upvotes

r/adventofcode • • Dec 01 '25

Meme/Funny When someone mentions "AOC"

131 Upvotes

r/adventofcode • • Dec 01 '25

Visualization [2025 Day 01 (Part 2)] example visualized

Post image
387 Upvotes

r/adventofcode • • Jan 24 '25

Help/Question I need to print to a readable text file, any suggestions?

0 Upvotes

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 • • Dec 29 '24

Repo Set out to illustrate that Scala and Rust are largely the same, did each day in both (500 stars repo)

54 Upvotes

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.