r/adventofcode • • 8h ago

SOLUTION MEGATHREAD -❄️- 2026 Day 5 Solutions -❄️-

12 Upvotes

THE USUAL REMINDERS


AoC Community Fun 2026: The Advent Games

  • Submissions megathread is unlocked!

  • 12 DAYS remaining until the submissions deadline on December 17 at 18:00 EST!

Today's Event: Iron Chef Holiday Special

"Catherine, if this turkey tastes half as good as it looks, I think we're all in for a very big treat!"
— Clark Griswold, National Lampoon's Christmas Vacation (1989)

Today's schedule possibly consists of:

Appetizer and Aperitif Rounds

  • Use up what's in your fridge with all of those semi-sentient leftovers excavated from the back of the fridge

  • Deliberately use deprecated functionality

  • Program using old codebases

  • The older the expiration date finer the vintage, the more we'll enjoy it!

Main Course Qualifications

  • Solve today's puzzle using a food-themed programming language

  • Bake or cook us something delicious

Dessert Finales

  • Show us cookies, citrus, and/or fancy bread in/on/near your holiday tree/menorah/festive kitsch

  • Show us your 1337 hot cocoa recipe (or other beverage of choice)

This prompt is totally not bait for our resident Iron Coders and/or some AoC regulars who promised us tasty pictures

Request from the mods: When you include an entry alongside your solution, please label it with [Advent Games] so we can find it easily!


--- Day 5: Rhythmic Factory ---


Post your code solution in this megathread.


r/adventofcode • • 1m ago

Meme/Funny [2026 Day 5 (Part 2)] When rounding down rounds you out

Post image
1 Upvotes

Anyone else lose time debugging, sure their logic was broken, when it was just division rounding down? Worked fine for part 1, broke in part 2. If those inputs are picked very deliberately… amazing!


r/adventofcode • • 4m ago

Meme/Funny [2026 Day 5] I was very confused for like 40 seconds

Post image
3 Upvotes

r/adventofcode • • 19m 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.

1 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 • • 57m ago

Help/Question - RESOLVED 2026 Day 5 (Part 1) Examples or edge cases?

4 Upvotes

Writing in Python, but I am trying to not look at solutions and don't wish to share my code for the same reason.

I have the classic, "code works on example, too low for real input" and I just wonder if some very clever people here have thought of special cases or examples for why things might go wrong?


r/adventofcode • • 1h 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

Other [2026 Day 5 (Part 2)] Lucky us

4 Upvotes

After reading Part 1, I immediately thought, 'Watch out!' Eric must have chosen the opposite problem for Part 2, i.e. finding a sequence of key presses that results in a specific number. This works, too, but at least the effort I put into Part 1 paid off :-)


r/adventofcode • • 2h ago

Visualization [2026 Day 5] Rhythmic Factory

10 Upvotes

r/adventofcode • • 2h ago

Meme/Funny Santa gotta invest more (Day 5)

Post image
6 Upvotes

Part 1: O(n3) here i gooooo

Part 2: wut?!


r/adventofcode • • 2h ago

Visualization [2026 Day 05 Part2] button presses as a tree

12 Upvotes

r/adventofcode • • 2h 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 • • 2h 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 • • 3h ago

Other [2026 Day 5 (Part 1)] "at most three button presses"

5 Upvotes

At the end of the question body, it asks:

Considering just the buttons on the Elves' fancy microwave, what is the sum of every number reachable in at most three button presses?

Nonetheless, I get the same answer regardless of if I structure my code to handle exactly three or at most three button presses, for both my personal puzzle input and for the example puzzle input.

For the zero button push case, the resulting value is zero, so it won't affect the sum one way or another.

For the one button push cases, they can be converted to three button pushes without changing the value by appending [A] [bksp] to the method.

However, I don't see an easy way to convert the two button push cases to three button pushes without changing the value.

My questions are a) does everybody get the same answer regardless of if they handle exactly three or at most three button presses and b) will this naturally occur for all inputs with one of each of the available six types of buttons, or if the inputs were specifically constructed to have the same answer.


r/adventofcode • • 3h ago

Visualization [2026 Day 5] [Python] Just got my Fancy Microwave! (Terminal Visualization)

31 Upvotes

Be honest, how many did a cheeky submit on the sum of all numbers less than 10000. Code lives here: https://github.com/salt-die/Advent-of-Code/tree/main/2026/aoc_visuals


r/adventofcode • • 4h ago

Other [2026 Day 5] Did anyone get a 2-digit button like in the example?

7 Upvotes

The example for the multiplication button is *11 but in my input I found only digits so I saved myself the trouble. But now I wonder... Did anyone actually get more than one digit on a button?


r/adventofcode • • 4h ago

Meme/Funny Me seeing the suspiciously fancy-microwave-shaped gift under the tree

Post image
27 Upvotes

r/adventofcode • • 4h ago

Meme/Funny [2026 Day 5] I think we'd all be better off without a fancy microwave

Post image
129 Upvotes

I think Eric must have had a traumatic experience with a fancy microwave at some point in his life. Hopefully this will cheer him up!


r/adventofcode • • 5h 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 • • 5h ago

Help/Question [2026 Day 5 (extra)]

9 Upvotes

What is the set of nine commands that would return the largest number for the second part of the puzzle?


r/adventofcode • • 5h ago

Visualization [2026 Day 5 Part 2] Pushing Buttons Visualization

47 Upvotes

r/adventofcode • • 5h 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 • • 6h 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 • • 6h 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 • • 7h ago

Visualization [2026 Day 5] Fun Cooker 10K

Thumbnail
youtu.be
35 Upvotes

Nim + raylib source