1
0
Fork 0
advent-of-code/2024/day01.py

31 lines
712 B
Python
Raw Permalink Normal View History

2024-12-03 08:43:55 +01:00
#!/usr/bin/env python3
lines = []
2024-12-03 15:09:37 +01:00
with open("./2024/inputs/day01.txt") as f:
2024-12-03 08:43:55 +01:00
lines = f.readlines()
left_column = []
right_column = []
for line in lines:
l, r = line.strip().split(" ")
left_column.append(int(l))
right_column.append(int(r))
left_column = sorted(left_column)
right_column = sorted(right_column)
diffs = [abs(left_column[x] - right_column[x]) for x in range(0, len(left_column))]
print(sum(diffs))
unique_nums = {}
for num in right_column:
if num in unique_nums.keys():
unique_nums[num] += 1
else:
unique_nums[num] = 1
sim_score = 0
for num in left_column:
if num in unique_nums.keys():
sim_score += num * unique_nums[num]
print(sim_score)