2024 - Day 1 part 2
This commit is contained in:
parent
05e956b7ae
commit
014b656137
1 changed files with 23 additions and 0 deletions
23
2024/1/1_2.py
Normal file
23
2024/1/1_2.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# 2024 - Advent Of Code 1 - part 2
|
||||||
|
|
||||||
|
# file = 'input_example.txt'
|
||||||
|
file = 'input.txt'
|
||||||
|
|
||||||
|
firsts = []
|
||||||
|
seconds = {}
|
||||||
|
accum = 0
|
||||||
|
with open(file, encoding="utf-8") as f:
|
||||||
|
for line in f.readlines():
|
||||||
|
a, b, c, d = line.strip().split(' ')
|
||||||
|
firsts.append(int(a))
|
||||||
|
if int(d) in seconds:
|
||||||
|
seconds[int(d)] += 1
|
||||||
|
else:
|
||||||
|
seconds[int(d)] = 1
|
||||||
|
|
||||||
|
for num in firsts:
|
||||||
|
if num in seconds:
|
||||||
|
accum += num * seconds[num]
|
||||||
|
|
||||||
|
print(f"sum: {accum}")
|
Loading…
Reference in a new issue