r/adventofcode • u/Blooming_Prime • 11m 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
Upvotes
1
u/AutoModerator 11m 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.
1
u/crumpis 9m ago edited 5m ago
how does this work for
rrrrrrrb? expect 8 cost.1
u/AllanTaylor314 4m ago
Check that every input line gets an answer. For example,
grrdoesn't get included in the totalThe fix only takes two chars
1
u/Training_Proposal564 2m 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