Day 01
This commit is contained in:
commit
ba4105f018
1 changed files with 24 additions and 0 deletions
24
day01.py
Normal file
24
day01.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from collections import Counter
|
||||
from functools import reduce
|
||||
|
||||
# 1
|
||||
|
||||
with open("day01") as f:
|
||||
lines = f.readlines()
|
||||
|
||||
els = [l.split() for l in lines]
|
||||
l1 = [int(el[0]) for el in els]
|
||||
l2 = [int(el[1]) for el in els]
|
||||
|
||||
l1.sort()
|
||||
l2.sort()
|
||||
|
||||
d = [abs(e[0] - e[1]) for e in zip(l1, l2)]
|
||||
res = sum(d)
|
||||
|
||||
|
||||
# 2
|
||||
ctn = Counter(l2)
|
||||
res = reduce(lambda accum, e: accum + e*ctn.get(e, 0), l1, 0)
|
Loading…
Reference in a new issue