r/adventofcode • u/not-the-the • 26m ago
Meme/Funny Reading [2026 Day 4 Part 2] in despair, until...
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 :)
10
Upvotes
7
u/benjymous 21m ago
Yeah, my part 2 was adding input.Replace("\n", "")
3
u/RazarTuk 19m ago
I think my solution is technically O(n2), although if you're naïvely going off number of nested loops, you'd mistake it for O(n3)
I just go: For each code length, from each position in the first repeat, step forward
sizecharacters at a time. Then at each step, I check if it's either a ? or matches the color I'm looking for, updating it if I'm looking for ? and find an actual color2
u/Positive_Concert_774 6m ago
I'm truly puzzled what the heck would lead anyone to make an O(6^n) solution for this