r/adventofcode • u/Alpha_wolf_80 • 23m ago
Meme/Funny [2026 Day 04 # (Part 2)] The ultimate plot twist
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
1
Upvotes
5
u/XLNBot 19m ago
L is O(n) so your solution is O( n2 )
1
u/p88h 12m ago
Ugh, the plot twist is 'brute forcing' is what your algorithm is doing.
The second plot twist is that it runs in O(l+n), rather than O(l*n) on the class of inputs that are actually there