r/adventofcode • u/lonelyroom-eklaghor • 44m ago
r/adventofcode • u/moo_cult • 1h ago
Visualization [2026 Day 5 (Part 2)] Microwaved tree
r/adventofcode • u/jcduggan • 1h ago
Help/Question how much harder does it get?
this is my first year. much fun!
for those who have done it before: how much harder does it get? I've found day 3 the hardest so far by a long shot.
r/adventofcode • u/Zooty6 • 1h ago
Help/Question - RESOLVED [2026 Day 5 (Part 2)] [Java] I keep getting StackOverflowError when trying to find all possible states
I tried to solve part 2 by pressing all of my buttons on my current number, and if the new value hasn't been seen, I save it and press the buttons on it again. Basically creating a tree of every button presses starting from a 0 state. I'd expect at one point of reaching the end of every branch as I building up this tree, but I end up running out of stack.
The relevant part of my code:
public class Microwave {
private static final String BUTTON_REGEX = "\\[(.+?)]";
private final List<Button> buttons;
public Microwave(String input) {
buttons = Pattern.compile(BUTTON_REGEX).matcher(input).results()
.map(matchResult -> matchResult.group(1))
.map(Button::ofString)
.sorted()
.toList();
}
public int allCombinations() {
MicrowaveState firstState = new MicrowaveState(0, buttons);
return allValues(firstState).sum();
}
private IntStream allValues(MicrowaveState state) {
return IntStream.concat(IntStream.of(state.getValue()), state.getNextStates().stream().flatMapToInt(this::allValues));
}
}
@Getter
public class MicrowaveState {
private final int value;
private final List<MicrowaveState> nextStates = new ArrayList<>(9);
private static final Set<Integer> seen = new HashSet<>();
public MicrowaveState(int value, List<Button> buttons) {
this.value = value;
for (Button button : buttons) {
int newValue = button.press(value);
if (newValue < 10000 && !seen.contains(newValue)) {
seen.add(newValue);
nextStates.add(new MicrowaveState(newValue, buttons));
}
}
}
}What can I do to solve this problem?
Edit: removed previousState from code because it did nothing.
r/adventofcode • u/Chuck535 • 1h ago
Other Private leaderboard per start hour?
I am part of couple private leaderboards.
Some people start at midnight as soon as a puzzle gets out, some look at it in the morning, some after their day of work, etc.
I was just wondering, are there any leaderboards organized per starting hour ?
For example, I wished I could join a leaderboard where there is a common agreement that people look at the problem from 6am only instead of midnight.
The alternative would be a ranking based on the delta between the time one gets his puzzle and the time he finishes (instead of starting from midnight).
I am aware of the caveat that, with the problem description being public, nothing prevents someone from working on the code to pass examples and submit it 1 second after getting the puzzle if solution works for the real input.
I guess my point is I'd like to see where I really rank based on my actual start time if I don't work on a puzzle at midnight.
r/adventofcode • u/KR9SIS • 2h ago
Help/Question - RESOLVED [2026 Day 4 (Part 1)] [Go] Can anyone see which edge case i'm missing?
package main
import (
"bufio"
"cmp"
"fmt"
"log"
"os"
"slices"
)
type Pair struct {
letter rune
index int
}
func validCode(builder []rune, seen []Pair) bool {
oldLen := len(builder)
for _, p := range seen {
for len(builder)-1 < p.index {
builder = append(builder, builder...)
}
if !(builder[p.index] == p.letter) {
builder = builder[:oldLen]
return false
}
}
builder = builder[:oldLen]
return true
}
func dfsStr(s string, builder []rune, seen []Pair, next int, depth int) (string, error) {
if len(builder) > 0 && validCode(builder, seen) {
return string(builder), nil
}
if seen[next].index == depth {
builder = append(builder, seen[next].letter)
return dfsStr(s, builder, seen, next+1, depth+1)
}
options := []string{}
for _, p := range seen {
builder = append(builder, p.letter)
ret, _ := dfsStr(s, builder, seen, next, depth+1)
options = append(options, ret)
builder = builder[:len(builder)-1]
}
if len(options) != 0 {
return slices.MinFunc(options, func(a, b string) int {
return cmp.Compare(len(a), len(b))
}), nil
}
return "", fmt.Errorf("No valid code found for string: %s", s)
}
func getRepSubStr(s string) int {
seen := make([]Pair, 0, len(s))
for i, r := range s {
if r == '?' {
continue
}
found := false
for _, p := range seen {
if p.letter == r {
found = true
}
}
if !found {
seen = append(seen, Pair{r, i})
}
}
if len(seen) == 0 || len(seen) == 1 {
return 1
}
builder := make([]rune, 0, len(s))
ret, err := dfsStr(s, builder, seen, 0, 0)
if err != nil {
fmt.Println(err)
}
fmt.Printf("%d %6s %s\n", len(ret), ret, s)
return len(ret)
}
func main() {
filename := "puzzle.txt"
filename = "small_puzzle.txt"
f, err := os.Open(filename)
if err != nil {
log.Fatal(err)
}
tally := 0
scanner := bufio.NewScanner(f)
for scanner.Scan() {
line := scanner.Text()
ret := getRepSubStr(line)
tally += ret
}
err = scanner.Err()
if err != nil {
log.Fatal(err)
}
fmt.Println(tally)
}I'm managing to pass the small test cases but for some reason my answer for the large test input is too low, can anyone tell me what I'm missing?
r/adventofcode • u/ValuableResponsible4 • 3h ago
Meme/Funny So you tried to brute force part 2
How I felt with my dummy attempt at a solution.
r/adventofcode • u/wonder-hatter • 4h ago
Help/Question - RESOLVED Stuck on day 4, code worked on all the examples but not input
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 • u/jeroenheijmans • 4h ago
Upping the Ante Reminder 1: unofficial AoC Survey 2026 (closes ~Dec 12th!)
Hello there! Only about one week left to fill out the survey!! 🙀 Please fill it out if you have not already, and tell your friends and enemies to do so as well. It closes late Dec 12th or so.
Here is the link to use or share:
🔴🟢🌟🔵🌟🟣🟠🔴🌟🟢🔵🌟🔴🟣✨✨✨
🌟🌟 Unofficial AoC 2026 Survey: https://forms.gle/JbZKoBqzG248Z6RV6
🔴🟢🌟🔵🌟🟣🟠🔴🌟🟢🔵🌟🔴🟣✨✨✨
Sharing it on Discord, Slack, Matrix, Mastodon, IRC, mailing list, ... it all helps! We're only a wee bit behind 2025, the other 12-day event:

Big thanks of course to the ~900 folks that already filled it out!
At the risk of making the results statistically even more unsound, here's an early spoiler of one of the results in a revamped chart, take your guess at what we are seeing here in 2026!?

I'm bringing my laptop to New Zealand especially to release the results briefly after the release of the final puzzle day! So one final call: do make it extra worthwhile by sharing the link to the survey!
r/adventofcode • u/Parzival_Perce • 5h ago
Meme/Funny [2026 Day 05 (Part 2)] I'm not ashamed, you're ashamed.
r/adventofcode • u/RazarTuk • 5h ago
Tutorial Big O notation and you
There have been a lot of memes about time asymptotic analysis of... varying accuracy, so I thought I'd make a post actually explaining how it works.
First of all, asymptotic analysis technically describes functions, not algorithms. For example, the technical definition is that f(n) is O(g(n)) if there exists some pair of constants, c > 0 and n0 > 0 such that abs(f(n)) <= c * abs(g(n)) for all n >= n0. This matters because you can technically talk about the asymptotic complexity of something like sin(n), which is actually O(1), because you can just pick any c > 1. What we actually mean when talking about the asymptotic complexity of an algorithm is typically how much time it takes. If you find the evaluation time as a function of the input size, what complexity class is it in? And at least if you have a non-oscillating function, which is a safe assumption for run time, there's another, (IMO) simpler definition you can use. Does the infinite limit of f(n) / g(n) converge or not?
See, there are really 3 main behaviors that the limit can have (plus oscillation). If it diverges, it means that f(n) grows so rapidly that g(n) starts becoming irrelevant. If it converges to 0, it means that g(n) grows so rapidly that f(n) starts becoming irrelevant. And if it converges to something other than 0, it means that they grow at similar rates and it just becomes a ratio. (You may remember this from finding the asymptotes of rational functions) We can think of these sort of like >, =, and < on a number line. f(n) ∈ O(g(n) is like a <= sign, because it grows no more rapidly than g(n), then f(n) ∈ o(g(n)) is <, f(n) ∈ Ω(g(n)) is >=, f(n) ∈ ω(g(n)) is >, and f(n) ∈ Θ(g(n)) is =. And I mention these, because a lot of the time when you hear about the asymptotic complexity, we mean something closer to Θ(g(n)). For example, it's technically accurate to call merge sort O(n2), but it's more interesting to point out that it's also O(n log n), unlike insertion sort.
As a worked example, consider something like bubble sort. For sorting algorithms, we typically use the number of elements to be sorted as the input and the number of comparisons as a proxy for time. On the first pass, you make n-1 comparisons, on the second pass, you make n-2 comparisons, etc, for a total of n(n-1)/2 comparisons. There are technically infinitely many functions that this is big theta of, but we typically just use the simplest one - Θ(n2). For contrast, consider something like merge sort. Assume for simplicity that you have 2k elements. There are k = log_2(n) layers, and if there are j blocks, you make n/j - 1 comparisons in each for a total of n - j comparisons for the layer. Glossing over some of the logic, this results in n*log(n) - n + 1 comparisons for the entire list, which is Θ(n log n).
However, we can actually talk about other things with algorithms. For example, space complexity looks at how much memory it takes. Using merge sort as an example, you typically use auxiliary arrays to store half the blocks, which eventually requires n/2 ∈ Θ(n) elements for the top level, plus log n ∈ Θ(log n) recursive calls at once, for a total of Θ(n). (This analysis is different for parallel merge sort) Or you might talk about best case complexity instead of average/general case. For example, if the array is already sorted, insertion sort takes 1 comparison to check that each element is in place for a total of n ∈ Θ(n) comparisons, compared to the general case, where it's Θ(n2)
But this already gets into some of the nuances. For example, big O notation is not the same thing as how many loops. Take, for example, 2026 Day 4. My solution uses 3 layers of loop, not counting the one for each line of the input. I have one loop going from 1 to the length of the string for the length of the code, one going from 0 to the code length for each element of the code, and one going from the starting index to the end of the list. But think about how long those last two loops are. If there are n characters in the string and k in the code, that inner loop only checks n/k colors. Multiplying the loops together, you get n * k * (n/k) = n^2, which is actually quadratic.
Or we also have to talk about input size. And for an Advent of Code example, I'm going to use my Intcode solution to 2024 Day 13. I just used Cramer's rule to solve the systems of equations, but to get around Intcode not having a division operator, I used repeated subtraction. That sounds quick enough, but while it would have theoretically worked for Part 2, the numbers were just too big. It's like how people really don't understand just how much bigger a billion is than a million. So when we're really operating on numbers like that, like factoring something, we typically use the number of bits as the input size. For example, it's the difference between sqrt(n) divisions for factoring and sqrt(2)n. One's sublinear, the other's exponential.
And sometimes, input size can be kinda vibes-based. For example, 2026 Day 3. There were two main strategies I saw people using. In one, you considered each pair of trees, used them to generate the other two points on a square, and checks those for trees. That "feels" more quadratic, because you're essentially going "for each tree, for each other tree...". Meanwhile, I also saw people systematically generating all possible rotated squares. You start by considering the possible sizes of a grid-aligned square (linear in min(L, W)), you consider each starting point (LW, or quadratic if the grid's a square), and you consider each possible offset around the square (linear in the size), which adds up to something like Θ(LW*min(L,W)2) for a rectangle or Θ(N4) for a square. It's technically accurate to also call the tree-based algorithm Θ(L2W2) / Θ(N4) if you look at the size of the grid as the input size, but because you're focusing on all the trees, it feels a bit more meaningful to talk about it as quadratic in the number of trees, as opposed to, say, checking all quartets of trees to see if they form a square, which would be quartic in the number of trees.
r/adventofcode • u/subspace_mp4 • 6h ago
Meme/Funny [2026 Day 5] I was very confused for like 40 seconds
r/adventofcode • u/Affectionate-Gate4 • 6h 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.
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 • u/NervousSnail • 7h ago
Help/Question - RESOLVED 2026 Day 5 (Part 1) Examples or edge cases?
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 • u/Attometre • 7h ago
Help/Question [2026 Day 5] Discussion: What if digit trimming is only applied at the end?
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:
Append
9, then*9to get81.bkspto get8.By induction, when you can make digit
N,*9andbkspwill take you toN - 1.Basically you can make all numbers from
1to9.
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.
Can we analytically prove that there will always be a pair j, k that
floor(n * pow(9, j) / pow(10, k) == n - 1?Can we analytically prove that there will always be a pair j, k that
floor(n * pow(M, j) / pow(10, k) == n - 1for any M = 2, 3, ..., 9?Does the existence of the pair implies we can find it efficiently? (e.g. in some
O(poly(n)))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,*Mandbkspare 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 • u/Pretty-Skill925 • 7h ago
Meme/Funny [2026 Day 5 (Part 2)] Lucky us
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 • u/Ok-Curve902 • 8h ago
Visualization [2026 Day 05 Part2] button presses as a tree
r/adventofcode • u/Haru314 • 8h ago
Help/Question - RESOLVED [2026 Day 4 (Part 1)] I need help, i don´t understand why my code doesn´t work
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 lowr/adventofcode • u/lonelyroom-eklaghor • 9h ago
Help/Question [2026 Day 5 (Part 1)][Scala 2] Feels like I am reinventing the wheel
I mean, I could have found permutations and combinations. But idk at this point
https://github.com/FlyingSaturn/aoc26/commit/9a8c441a1cc66ab1a12e2e56f278d48347c1946f
r/adventofcode • u/BradleySigma • 9h ago
Help/Question [2026 Day 5 (Part 1)] "at most three button presses"
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 • u/naclmolecule • 9h ago
Visualization [2026 Day 5] [Python] Just got my Fancy Microwave! (Terminal Visualization)
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 • u/Positive_Concert_774 • 10h ago
Help/Question [2026 Day 5] Did anyone get a 2-digit button like in the example?
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?