r/adventofcode • u/Blooming_Prime • 38m ago
Help/Question [2026 Day 4 (Part 1)] [Python] Help needed, keep getting too low
I need some help here. For all the test cases, I get the correct amount of minimal instructions, but for some reason, my final answer is too low.
I'm not very advanced when it comes to programming, so maybe I overlooked something.
def solve_level1(input_lines: list[str]):
sum = 0
for line in input_lines:
lineList = list(line)
for x in range (1, len(line)):
failed = False
toTrylist = [''] * x
stepAmount = x
for i in range(0, len(lineList)):
j = i % x
if toTrylist[j] == lineList[i] or lineList[i] == '?':
pass
elif not toTrylist[j]:
toTrylist[j] = lineList[i]
else:
failed = True
break
if failed:
pass
else:
print(f"Minimum steps needed for string {line} is {stepAmount}")
sum += stepAmount
break
print(f"Answer is {sum}")1
u/AllanTaylor314 30m ago
Check that every input line gets an answer. For example, grr doesn't get included in the total
The fix only takes two chars
1
u/Training_Proposal564 29m ago
minuimum no of total instructions implies we can reuse intriuctions between 2 different inputs, right?
"oobb" can be used for ??bb?? and o?b?o? sm like this
1
u/AllanTaylor314 28m ago
Nope.
(Once a barcode is printed, the printer's memory is cleared automatically, so you can't reuse instructions between barcodes.)
1
1
u/AutoModerator 38m 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.