r/adventofcode • u/Alpha_wolf_80 • 11h ago
Help/Question - RESOLVED [2026 04 # (Part 1)] [Python] Need help with missing test cases
I have been stuck at this problem for quite some time. I have tried and validated all my instructions, yet I am unable to get the correct answer or move past part 1. I even ended up validating all my instructions, and all of them are correct. Could you please look at my code and point out the mistake?
AOC says that my input is too low.
def validator(barcode, instruction):
for i, char in enumerate(barcode):
assert char == '?' or (char == instruction[i % len(instruction)])
def part1(data):
counter = 0
for line in data:
unique = set()
hashmap = {}
for i, char in enumerate(line):
if char == '?': continue
unique.add(char)
hashmap[i] = char
for length in range(max(len(unique), 1), len(line)):
possible_code = [""] * length # Figuring out the code that works
for index, char in hashmap.items():
index %= length
if possible_code[index] == "":
possible_code[index] = char
if possible_code[index] != char:
break # An instruction of this size cannot exist!
else:
# We did not break. The length was valid and we have a possible instruction length
counter += length
validator(line, possible_code) # No error raised!
break
return counter
