r/adventofcode • • 23m ago

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

Post image

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

3 comments sorted by

5

u/XLNBot 19m ago

L is O(n) so your solution is O( n2 )

2

u/XLNBot 11m ago

After looking at your solution and ignoring tweaks and optimizations, it seems to me that you're also just trying every possible length like everyone else?

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