31 lines
No EOL
712 B
Python
31 lines
No EOL
712 B
Python
#!/usr/bin/env python3
|
|
|
|
lines = []
|
|
with open("./2024/inputs/day01.txt") as f:
|
|
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) |