added day 07
This commit is contained in:
23
07/solve01.py
Normal file
23
07/solve01.py
Normal 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))
|
||||
Reference in New Issue
Block a user