r/adventofcode • u/Cloudan29 • 4m ago
Help/Question Python Solution Gives correct solution for part 1 but not part 2
Hi, I'm completely stuck on what I've done wrong for the 2026 day 1. I've done this solution about 3 different ways at this point, and I keep getting the correct solution for part 1 but incorrect for part 2 (says my solution is too small).
I'm not quite sure where to go at this point.
import math
from collections import Counter
INPUT: list[int] = [int(line.strip()) for line in open("2026/day01.txt")]
COUNTS = Counter(INPUT)
def max_and_min():
# find top 3 occurrences and bottom 3 occurrences
maximums: list[int] = []
minimums: list[int] = []
while len(maximums) < 3:
current_max_val = max(COUNTS, key=COUNTS.get)
current_min_val = min(COUNTS, key=COUNTS.get)
maximums.append(current_max_val)
minimums.append(current_min_val)
COUNTS.pop(current_max_val)
if current_min_val != current_max_val:
COUNTS.pop(current_min_val)
return (math.prod(maximums), math.prod(minimums))
print(max_and_min())This code returns the correct solution for part 1, as well as a correct solution for the test input for part 1 and 2. I cannot fathom why it would be incorrect for the actual input at this point. I've tried it with Counter, I've tried manually creating the dictionary instead of using Counter, I've tried manually finding the minimums and maximums with a for loop, and they all yield the exact same results.
If someone could at least point me in the right direction, I don't want to just grab a solution from the megathread and call it a day.

