aoc-2024/1/2.py

28 lines
627 B
Python
Raw Normal View History

2024-12-03 08:39:30 +00:00
def counts(nums: list[int]) -> dict[int, int]:
ret = {}
for n in nums:
if n in ret:
ret[n] += 1
else:
ret[n] = 1
return ret
if __name__ == '__main__':
with open('1.input') as file:
left, right = [], []
for line in file:
l, r = line.split()
l, r = int(l), int(r)
left.append(l)
right.append(r)
# how many times does each number apear in each list
right = counts(right)
score = 0
for n in left:
if n not in right: continue
score += n * right[n]
print(score)