Add 2024/day1/part2.py
This commit is contained in:
parent
f97b157d72
commit
2603cda612
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from collections import Counter
|
||||
|
||||
list1 = [];
|
||||
list2 = [];
|
||||
with open("input.txt") as file:
|
||||
for line in file:
|
||||
if line.strip():
|
||||
num1,num2 = map(int, line.split())
|
||||
list1.append(num1)
|
||||
list2.append(num2)
|
||||
|
||||
counts = Counter(list2)
|
||||
|
||||
result = 0;
|
||||
for num in list1:
|
||||
if(counts.get(num)):
|
||||
result+=num*counts.get(num)
|
||||
|
||||
print(f'Result: {result}')
|
Loading…
Reference in New Issue