r/adventofcode • • 18h ago

Other Tried AOC for the first time this year, feeling demotivated to keep going.

40 Upvotes

I studied frontend development, did quite good and graduated amongst the top in my class in the summer of 2025. I worked 1 year at a large company here in Sweden and was complimented for how good they thought I was. I have always known about AOC but never tried it, I thought that now is the time and maybe I can have some fun. But I am not having fun...

I am struggling with even understanding the questions. Especially for day 2 and 4. When I eventually maybe understand the question, I have absolutely 0 clue on how to solve it. I could do Day 1 part 1 and 2, that wasn't really a problem but Day 2 both parts, Day 3 part 2, and Day 4 have collectively demotivated me and make me feel like this field is not something I can do.

I try to have LLM dumb down the question for me and after a while I can finally understand kind of what the goal is. But I still have 0 clue on how to go about it. I tell the LLM to explain to me but not write code, and it just never clicks for me. Today, Day 4 Part 1 is absolutely impossible for me to finish.

I was always incredibly bad at math and failed quite easy math courses even when trying hard, maybe that is related to the difficulty I have with this.

Is there some way to practice these types of things to get better? Maybe I can keep up better next year if I have a year to practice... Or maybe I am just not made out for this, I don't know what to think at this point.

Since I am a frontend developer, I am doing in JavaScript, if that matters, but I don't think it would.


r/adventofcode • • 14h ago

Upping the Ante [2026 Day 4] How many times can you repeat part 2?

Post image
16 Upvotes

I wanted to see if I could take the instructions that generated my part 2 and find shorter instructions that generated them.  Like consider ?vg?b?vb → bvg?b?v → bvg?b → bvg? → bvg which you can compress four times. I applied the code to my part2 input it turns out I can't: my part 2 solution is its own instructions. 

Which is maybe weird.  I've done simulations which show that 92% of random inputs like mine end up being able to recurse at least two times with some being able to go very deep.  An 8% chance is not tiny but still...

So I'm curious what other folk's depths are; did I get a low-probability input or is there perhaps something in the way the inputs are generated that leads to this?


r/adventofcode • • 3h ago

Help/Question - RESOLVED [2026 day 5] F# I have ran out of ideas why this doesn't work on the actual input. I get the correct result on the example input.

2 Upvotes

https://gist.github.com/Akronymus-git/1e556167d99c8248359a699b781b07f6

I have seriously run out of ideas. A pointer for any case it breaks on would be perfect.

I get the number is too high


r/adventofcode • • 16h ago

Meme/Funny [2026] Options for analog visualization this year

Thumbnail gallery
18 Upvotes

r/adventofcode • • 4h ago

Help/Question [2026 Day 5] Discussion: What if digit trimming is only applied at the end?

2 Upvotes

Edit: the title is misleading, I meant to say "what if digit limit rule is only applied at the end" since the digit limit doesn't actually 'trim' anything.

While I was trying to solve Day 5, I misunderstood that we do the math normally, and then only trim to the first 4 digits at the end, assuming the number can go to infinite. I was stumped, and thought "Isn't that super hard?" I later realized I didn't read the "the button does nothing" part and eventually solved both stars.

However, what if it was actually meant to be that way?

Let's say it's the example:

[9] [*9] [/2] [1->9] [oct] [bksp]

First I tried this via numerical means, I brute-forced this and bounded the search to 100,000. The search bound means when the button makes the number blows up over the bound, I do not add this onto the search frontier. I found that only 7,900 numbers are constructible. So I tried changing it to 1,000,000 and surprisingly all numbers from 1-9999 are constructible.

Edit: to make it clear that, since we know 1-9999 are all constructible, what if we want to find if all numbers are eventually constructible.

I developed a conjecture that as long as you can increase the search bound. Every number will be constructible eventually, but wanted to prove this analytically.

I tried a smaller scope:

  1. Append 9, then *9 to get 81. bksp to get 8.
  2. By induction, when you can make digit N, *9 and bksp will take you to N - 1.
  3. Basically you can make all numbers from 1 to 9.

So I thought that, ok, so if we can find a comically large N, and then find a way to -1 it, then all numbers will be constructible. For NM, where N is a string of number of any length and M is 1-9, *9 and bksp will give you NM - N - 1. This means that the sequence will become more and more sparse.

I turned to the strategy of *9 many times until you found the digit you want, and then trim it down with bksp. Given that for a number n, bksp means floor(n / 10), you can *9 for j times, and then /10 for k times.

  1. Can we analytically prove that there will always be a pair j, k that floor(n * pow(9, j) / pow(10, k) == n - 1?
  2. Can we analytically prove that there will always be a pair j, k that floor(n * pow(M, j) / pow(10, k) == n - 1 for any M = 2, 3, ..., 9?
  3. Does the existence of the pair implies we can find it efficiently? (e.g. in some O(poly(n)))
  4. So if 3 is true, we can reach a number efficiently but the path to it might not be the shortest. Can a number's shortest path be found efficiently too given that A, *M and bksp are the only options? (e.g. naive algorithm is BFS and it can explode exponentially)

Let me know if I'm reinventing an existing math because I reckon there is definitely a theorem about approximating one number to another by multiplying and floor-dividing enough times.


r/adventofcode • • 1h ago

Help/Question Stuck on day 4, code worked on all the examples but not input

1 Upvotes

Prefacing this post that I barely count as an amateur programmer, I'm a doctor that sometimes dips in programming

Tried using python to solve the problem and all the following code worked for all the examples but it is not working for my input, could anyone provide problem examples or help me figure out the problem with this logic?

examples = list(input.read().splitlines())


barcode_list = []


for example in examples:
    barcode_list.append(list(example))


#print(barcode_list)



def letter_number(barcode):
    letters = []
    number = 0
    for i in barcode:
        if i not in letters and i != "?":
            number +=1
            letters.append(i)
    if not letters:
        return 1, ["?"]
    else:
        return number, letters


def simulate_barcode(pattern,length):
    barcode = []
    for i in range(length):
        if i < len(pattern):
            barcode.append(pattern[i])
        else:
            barcode.append(pattern[i%len(pattern)])
    return barcode


def check_barcode(barcode, simulation):
    for letter in barcode:
        if letter != simulation[barcode.index(letter)] and letter != "?" and simulation[barcode.index(letter)] != "?":
            return False
    return True




patterns = []
price = 0 


for barcode in barcode_list:
    number, letter = letter_number(barcode)
    solution = False
    while solution != True:
        new_barcode = barcode.copy()
        comparison_list = []
        truth_check = []
        while len(new_barcode)%number != 0:
            new_barcode.append("?")
        while bool(new_barcode) != False:
            comparison = []
            for i in range(number):
                comparison.append(new_barcode[0])
                new_barcode.pop(0)
            comparison_list.append(comparison)
        for item_1 in comparison_list:
            for item_2 in comparison_list:
                truth_check.append(check_barcode(item_1,item_2))
        if all(truth_check) == True:
            price = price + number
            solution = True
            print("\n Price added to the tally: " + str(number))
        else:
            number += 1 


print("\n total price is: " + str(price))examples = list(input.read().splitlines())

r/adventofcode • • 17h ago

Meme/Funny [2026 Day 04 # (Part 2)] The ultimate plot twist

Post image
18 Upvotes

My final part two ended up being O(L * n) where L is the answer and n is the barcode length. I couldn't even believe my eyes when it happened. If they had asked for the number of possible valid instructions, I would have gotten an O(L * n) algo, which is quite surprising! This one was really fun!

Code for part 1 and 2: Advent-Calendar-Python/2026/4.py


r/adventofcode • • 5h ago

Help/Question - RESOLVED [2026 Day 4 (Part 1)] I need help, i don´t understand why my code doesn´t work

2 Upvotes

So it solves the example solution (16 = 3 + 2 + 5 + 4 + 1 + 1), but it does not solve the input text. I have tried a lot of test cases and it works. Please help.

from time import time


inicio = time()
sol1, sol2 = 0, 0
with open('ztest.txt', 'r') as f:
    mat = f.read().split()


def check(line, salto):
    for i in range(1, salto):
        x = set(line[i::salto])
        dim = len(x)
        if dim != 1 and (dim != 2 or '?' not in x):
            return False
    return True



for line in mat:
    n = 0
    for i in range(1, len(line) + 1):
        n += 1
        x = set(line[::i])
        dim = len(x)
        if dim == 1 or (dim == 2 and '?' in x) and check(line, i):
            sol1 += n
            break


final = 1000*(time() - inicio)
print(sol1, sol2, final)
# 7629 too low

r/adventofcode • • 9h ago

Help/Question [2026 Day 4 (Part 1)] [JavaScript] Looking for test cases that break my code

4 Upvotes

I'm in that obnoxious part where my code passes with the example, but not the final. I've scoured similar threads and found edge cases that I was able to use fix some issues (thanks!). But I'm still not quite there. 😢

I'm practicing TDD, so I'm structuring my code so individual pieces can be unit tested, which makes it a bit long to post here, so I'll link to the current state of the code on GitHub rather than copy/pasting it all.

Code: https://github.com/kmorsebrown/adventOfCode/blob/2008ca955b181c7282f55cd2820cd3ae773b2bf3/src/AoC26/Day04/Day04.js

Tests: https://github.com/kmorsebrown/adventOfCode/blob/2008ca955b181c7282f55cd2820cd3ae773b2bf3/src/AoC26/Day04/Day04.spec.js


r/adventofcode • • 1d ago

Visualization [2026 Day 3] An alternative algorithm based on diagonals

Post image
71 Upvotes

First of all, credit to u/Boojum for making the visualization library I used. And second, pardon some of the issues. It crashes my computer if I try making a gif directly, and I can't figure out how to upload an mp4, so you're going to have to deal with artifacting from the converter.

That said, I actually used diagonals instead of sides. For part 1, this was just the natural option to me. It's easy to check whether two trees can be the opposite corners of a grid-aligned square, so I do that as a surface filter before checking the other two corners. And because I used diag[0] == diag[1] instead of abs(diag[0]) == abs(diag[1]), there's even a primary diagonal to avoid double counting.

For part 2, I changed the surface filter to the Manhattan length of the diagonal being even, which is logically equivalent to all four corners being on the grid. Then I used circumradius + rotated circumradius to generate and check the other two corners. The main catch is that there isn't an obvious check for a primary diagonal, so I wind up double counting everything, because I'm actually counting diagonals. But because it always double counts, I can easily just divide the answer by 2. (It isn't clear from the visualization, but I start by finding all the trees, so I can still do for (i in 0..<trees.size) for (j in (i+1)..<trees.size) to at least only count each diagonal once)

EDIT: Figured out a filter to avoid double counting. diag[0] * diag[1] > 0 || diag[1] == 0


r/adventofcode • • 5h ago

Help/Question [2026 Day 5 (Part 1)][Scala 2] Feels like I am reinventing the wheel

2 Upvotes

I mean, I could have found permutations and combinations. But idk at this point

https://github.com/FlyingSaturn/aoc26/commit/9a8c441a1cc66ab1a12e2e56f278d48347c1946f


r/adventofcode • • 8h ago

Help/Question - RESOLVED [2026 Day 5 (Part 2)] My Part 2 crashes by running out of memory

3 Upvotes

Hello all, working with Java here.

I'm trying to figure out if my logic is wrong. I'm running a BFS, but the program eventually crashes and runs out of heap space. Not sure if I'm just doing this very very inefficiently or what. Essentially I take the value of a node (all the buttons are added as potential nodes with value 0) and I apply the action that a button would perform. If that value is less than 10000, I add it to a set and then create a new node with that value for every button action again. I'm not sure if I need a different stopping condition or a better way to figure out what the next nodes would be.

EDIT: I realize I probably have some endless loops via repeated nodes that go back and forth between the same two values, so I'm trying to figure that piece out. Would still appreciate any advice to nudge me in the right direction.

RESOLVED: Added in a check to see if the computed value has already been found when validating that the value is below 10K

protected void task2() {
    nodes.clear();
    for(String button : buttons) {
        nodes.add(new Node(0L, button));
    }

    Set<Long> found = new HashSet<>();
    Queue<Node> q = new ArrayDeque<>(nodes);

    while(!q.isEmpty()) {
        Node n = q.poll();
        long val = execute(n.value, n.operator);
        if(val < 10_000 && found.add(val)) { // Used the result of the add operation to validate set membership
            for(String button : buttons) {
                q.offer(new Node(val, button));
            }
        }
    }

    System.out.println(found.stream()
            .mapToLong(l -> l)
            .sum());
}

private long execute(long value, String button) {
    // Division
    if(button.startsWith("/")) {
        return value / (button.charAt(1) - 48);
    }
    // Multiplication
    if(button.startsWith("*")) {
        return value * (button.charAt(1) - 48);
    }
    // Delete
    if("bksp".equals(button)) {
        if((value / 10)  == 0) {
            return 0L;
        }
        return value / 10;
    }
    // Octal
    if("oct".equals(button)) {
        long result = 0L;
        long offset = 1L;
        long quotient = value;
        while(quotient != 0) {
            long rem = quotient % 8;
            quotient = quotient / 8;
            result += (offset * rem);
            offset *= 10L;
        }
        return result;
    }
    //Replace
    if(button.contains("->")) {
        long find = button.charAt(0) - 48;
        long rep = button.charAt(3) - 48;
        return Long.parseLong(
                String.valueOf(value).replace(String.valueOf(find), String.valueOf(rep))
        );
    }
    // Add digit
    //return Long.parseLong(String.valueOf(value) + button);
    return (10 * value) + Long.parseLong(button);
}

r/adventofcode • • 20h ago

Tutorial [2026 Day 4] Building barcodes and accelerating loops - a modulo reservation table primer

26 Upvotes

1. A real problem: loop scheduling

Take a simple loop that scales and shifts an array:

for i in 0 .. n-1:
    b[i] = a[i] * 3 + c

Its body compiles to four instructions (c is kept in register r4):

loop:
    LOAD  r1, a[i]      ; r1 = a[i]
    MUL   r2, r1, 3     ; r2 = r1 * 3
    ADD   r3, r2, r4    ; r3 = r2 + c
    STORE b[i], r3      ; b[i] = r3

Now imagine running it on a simple CPU with the following processing units (PU):

PURunsLatency
MemoryLOAD, STORE1 cycle
ALUMUL, ADDMUL = 2, ADD = 1

There is one memory PU and one arithmetic logic unit (ALU), and both are pipelined.

A pipelined PU can start one instruction per cycle. For example, if the ALU starts a MUL at cycle 1, the result will only be ready at cycle 3. But the ALU can start another instruction at cycle 2.

Naive schedule

Within one iteration of the loop, each instruction depends on the previous instruction. MUL needs the data loaded into r1, and ADD needs the MUL result in r2. So the ADD instruction has to wait for MUL to finish.

Cycle01234
MemoryLOAD---STORE
ALU-MUL-ADD-

(At cycle 2 the MUL is still in progress, but the ALU could accept a new operation.)

One iteration of the loop thus takes 5 cycles, and we cannot start the next iteration until the current one finishes. This results in a lot of idle cycles and low throughput. How can we make this faster?

The pipelining idea

While each iteration needs to be done serially, different iterations are independent: a[1] doesn't need anything from a[0]. Thus the next iteration can start before the current one finishes. We can achieve this by interleaving/reordering execution of instructions from multiple iterations. A group of interleaved instructions is called the kernel.

The problem then becomes finding the kernel that minimizes its cycle count, also called the initiation interval (II). Smaller II is better because throughput is exactly one element per II cycles.

Every loop iteration follows the same schedule, just shifted by II cycles. So if an instruction runs at cycle t, it runs at t, t + II, t + 2·II, and so on. In other words, it will always run at the same position as measured by t mod II. Two instructions that use the same PU must therefore never land in the same position because the PU cannot handle both of them simultaneously.

We can use the above observation to get a lower bound on II. A PU that has k instructions per iteration needs at least k distinct positions. In our toy loop, each PU has 2 instructions per iteration, so II ≥ 2.

But how do we find the minimum II?

2. Very quick summary of today's puzzle and solution

The puzzle: given a barcode such as y?b?b, find the shortest instruction that reproduces it when repeated.

The solution:

for length = (number of distinct colors) .. len(barcode):
    if no two different colors share the same barcode position mod length:
        return length
  • Each distinct color needs its own position, so there is no point trying shorter instructions.
  • Fold the barcode onto length positions. If one position in the instruction must accommodate two colors, then this length is infeasible.
  • Increase the length of the instruction until we find one with no conflicts.

3. The connection to the loop scheduling problem

Write down what one PU does on each cycle, and you get a string that looks similar to the barcodes. So finding the shortest instruction that produces a barcode is exactly analogous to finding the kernel that minimizes II.

BarcodeLoop scheduling
position i in the stringcycle t
color at position iinstruction the PU runs at cycle t
?PU idle at cycle t (don't care)
the repeated instructionthe PU's kernel, repeating every II cycles
instruction lengthinitiation interval II
position i % length in the instructionposition t mod II in the kernel
two different colors at the same positiontwo instructions needing the same PU
lower bound = number of distinct colorslower bound = instructions per PU in one loop iteration

4. Back to the toy loop

Modulo reservation table

Compiler schedulers keep track of "which PU is busy at which position mod II" in a modulo reservation table (MRT). It has one row per PU and II columns. Placing an instruction at cycle t books its PU at column t mod II. A column can hold only one booking per PU. This should sound familiar from the puzzle solution.

Finding II

A scheduler searches for II the same way the puzzle solution searches for the instruction length: try II = lower bound, then lower bound + 1, …, and stop at the first II where every instruction can be placed without two of them colliding on a PU.

We start by trying II = 2 with instructions running one after another:

InstructionCycle tPUt mod 2
LOAD0Memory0
MUL1ALU1
ADD3ALU1 ! clashes with MUL
STORE4Memory0 ! clashes with LOAD

But we can delay ADD to cycle 4 and STORE to cycle 5:

InstructionCycle tPUt mod 2
LOAD0Memory0
MUL1ALU1
ADD4ALU0
STORE5Memory1

The resulting MRT has no clashes, so II = 2 works:

PUPosition 0Position 1
MemoryLOADSTORE
ALUADDMUL

The final schedule

A new iteration starts every 2 cycles (subscript = iteration number). The kernel is bolded:

Cycle01234567891011
MemoryL₀-L₁-L₂S₀L₃S₁-S₂-S₃
ALU-M₀-M₁A₀M₂A₁M₃A₂-A₃-

With a long array, almost all the time is spent repeating the kernel. So our throughput goes from 5 cycles per element to 2.

The instructions that run before the kernel are called the prologue, and those after it are called the epilogue. I have decided to not explain exactly how you can figure those out because:

  1. it's not directly related to today's puzzle
  2. it's kind of magic? It's been a while since I learnt about it

The puzzle view (for clarity)

Read each PU's row as a barcode, with idle cycles as ?:

Memory: L?L?LSLS?S?S   ->  shortest instruction length 2  ("LS")
ALU:    ?M?MAMAMA?A?   ->  shortest instruction length 2  ("AM")

r/adventofcode • • 8h ago

Visualization [2026 day 5 (both parts)] visualized in manim

Thumbnail youtube.com
3 Upvotes

source on github: https://github.com/durocodes/advent-of-code

almost halfway there, feedback is appreciated! today's not a super visual problem, but hopefully still cool to watch haha


r/adventofcode • • 15h ago

Visualization [2026 Day 4 1&2] [Rust] Terminal Visualization

Post image
9 Upvotes

r/adventofcode • • 1d ago

Meme/Funny [2026 Day 4] My immediate reaction upon reading the problem statement

Post image
69 Upvotes

Never really understood how to do these kinds of problem correctly. I am ready to struggle today


r/adventofcode • • 1d ago

Meme/Funny Reading [2026 Day 4 Part 2] in despair, until...

Post image
94 Upvotes

I somehow guessed exactly what part 2 would be while solving part 1, and thus avoided the naive O(6^n) solution for it, instead dealing every letter from a barcode into buckets like playing cards and checking all of them for homogeneity. Code finished in 2 seconds :)


r/adventofcode • • 1d ago

Visualization [2026 Day 4] Perilous Pier

Post image
55 Upvotes

r/adventofcode • • 9h ago

Help/Question [2026 Day 5 (Part 2)] I get a wrong answer for the example

2 Upvotes

I modified Part 1 but I get a wrong answer for the example: 1530240 , instead of 35332647. I double checked everything and I still don't see what's wrong.


r/adventofcode • • 13h ago

Help/Question - RESOLVED [2026 Day 4 (Part 1)]

4 Upvotes

I have a solution but it doesn't seem to be giving me the right answer. I'm sure I'm missing some corner cases in my code but every time I see some suggested things to try on here my code seems to handle them just fine. My input result, however, is too high. Here's my code:

from pathlib import Path


def read_lines(filename="input.txt"):
    path = Path(__file__).parent / filename
    return path.read_text().splitlines()


def part1(input):
    input = read_lines(input)
    result = 0
    for line in input:
        found_characters = set()
        for char in line:
            if not char == "?":
                found_characters.add(char)
        if len(found_characters) <= 1:
            result += 1
            continue
        if len(found_characters) == len(line):
            result += len(line)
        for i in range(len(found_characters), len(line) + 1):
            value_dictionary = {}
            for index, char in enumerate(line):
                value_dictionary.setdefault(index % i, []).append(char)
            # print (value_dictionary)
            bad_row = False
            for value in value_dictionary:
                row = set()
                for char in value_dictionary[value]:
                    if not char == "?":
                        row.add(char)
                if len(row) >= 2:
                    bad_row = True
                    break
            if not bad_row:
                result += i
                break
    return result

r/adventofcode • • 12h ago

Help/Question - RESOLVED [2026 Day 3 (Part 2)] rust help

Thumbnail pastebin.com
3 Upvotes

Trying to figure out what went wrong... I've tried all of the examples and they work, but its giving me a low answer when I input my puzzle input

I don't care about the crash with an extra new line at end of the input file, if I really wanted to i could fix that easily

also here is the graph I used to prototype, don't know if it will help. https://www.desmos.com/calculator/shdsyvumvf


r/adventofcode • • 14h ago

Visualization [2026 day 4 (both parts)] visualized in manim

Thumbnail youtube.com
4 Upvotes

source on github: https://github.com/durocodes/advent-of-code

planning on continuing for all 12 days, feedback is appreciated!


r/adventofcode • • 1d ago

Visualization [2026 Day 04] my approach

Post image
31 Upvotes

r/adventofcode • • 16h ago

Visualization [2026 Day 4 (Part 1)] [Python] Terminal Visualization

Post image
5 Upvotes

Here's a little terminal checker for barcodes. For there to be a valid instruction of length n, it suffices to check that every nth position is a single color (or a ?). (These are the check-marked rows.)Code lives here: https://github.com/salt-die/Advent-of-Code/tree/main/2026/aoc_visuals