added day 07

This commit is contained in:
Peter Hudec
2021-12-07 06:52:13 +01:00
parent 3e08ac5853
commit 2f6c0a9943
4 changed files with 49 additions and 0 deletions

23
07/solve01.py Normal file
View File

@ -0,0 +1,23 @@
#!/usr/bin/python
import sys
from collections import defaultdict
with open("input01.txt","r") as f:
data = [int(i) for i in f.readline().split(',')]
count = defaultdict(int)
for i in data:
count[i] += 1
pos_min = min([i for i in count.keys()])
pos_max = max([i for i in count.keys()])
results = []
for pos in range(pos_min, pos_max+1):
tmp = 0
for i in count.keys():
tmp += abs(pos-i)*count[i]
results.append(tmp)
print(min(results))