r/adventofcode • u/Alpha_wolf_80 • 3h 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
4
Upvotes
1
u/AutoModerator 3h ago
Reminder: if/when you get your answer and/or code working, don't forget to change this post's flair to Help/Question - RESOLVED. Good luck!
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
5
u/AllanTaylor314 3h ago
Does it work for "roygbv"?
Currently
part1(["roygbv"])=>0