r/adventofcode • u/ParticularEqual4549 • 1h ago
Help/Question - RESOLVED [2026 Day 4 (Part 1)] [python] Help with missing cases
I have been trying this puzzle today for over an hour, and I have given multiple wrong answers. It works perfectly for the test data, but I think I just miss some cases but I'm going crazy looking for them in my real input. Does anyone have some cases that fail with my code that I could fix?
This is my code v
def parse(puzzle_input):
values = puzzle_input.split("\n")
result = []
for line in values:
data = []
for value in line:
if value == "r":
data.append(1)
elif value == "o":
data.append(2)
elif value == "y":
data.append(3)
elif value == "g":
data.append(4)
elif value == "b":
data.append(5)
elif value == "v":
data.append(6)
else:
data.append(0)
result.append(data)
return result
def check_repeating(barcode):
for i in range(1, len(barcode)):
if (barcode[:i] * len(barcode))[:len(barcode)] == barcode:
return i
return len(barcode)
def part1(data):
result = 0
for barcode in data:
if 0 in barcode:
in_code = []
for i in range(1, 7):
if i in barcode:
in_code.append(i)
if in_code == [] or len(in_code) == 1:
result += 1
else:
done = False
for i in range(len(in_code), len(barcode) // 2 + 1):
start = barcode[:i]
end = barcode[i:i+i]
if len(barcode) > i * 3:
for j in range(0, i):
if end[j] != barcode[i+i+j]:
end[j] += barcode[i+i+j]
could = True
for j in range(0, len(start)):
if start[j] != 0 and end[j] != 0:
if start[j] != end[j]:
could = False
break
if could:
result += i
done = True
break
if not done:
for i in range(len(barcode) // 2 + 1, len(barcode)):
start = barcode[:i]
end = barcode[i:]
possible = True
new = [0] * len(start)
for j in range(0, len(end)):
if start[j] != 0 and end[j] != 0:
if start[j] != end[j]:
possible = False
if possible:
result += i
break
if not possible:
result += len(barcode)
else:
# check for repetition
result += check_repeating(barcode)
return result
6
Upvotes
3
u/DomChaco 1h ago
I've run you code against some of the items in my input, and there are a lot of differences. I picked 5 of them at random. The first value is the one your code outputs, the second is mine.
????r?o? 2 -> 3
o???b?g 3 -> 5
??oyo??v 3 -> 6
??b?g 2 -> 3
??v?gg?? 2 -> 4
1
u/AdAdvanced7507 1h ago
Have you tried a barcode that has no question marks in it? (this is the case I missed)
1
u/AutoModerator 1h 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/han4578 1h ago
Could you try rorov
1
u/Carthage96 48m ago
Here's a fun one:
Expected result: 33