day 1
parent
02ba7c97f9
commit
f85cbb1539
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,6 @@
|
|||
3 4
|
||||
4 3
|
||||
2 5
|
||||
1 3
|
||||
3 9
|
||||
3 3
|
|
@ -0,0 +1,3 @@
|
|||
) read "data.ivy"
|
||||
|
||||
a
|
|
@ -0,0 +1,18 @@
|
|||
#input = open("sample1.in")
|
||||
input = open("input")
|
||||
|
||||
nums = [[int(x) for x in line.split()] for line in input]
|
||||
|
||||
# part 1
|
||||
a = [x[0] for x in nums]
|
||||
b = [x[1] for x in nums]
|
||||
a.sort()
|
||||
b.sort()
|
||||
distance = [abs(x-y) for x,y in zip(a,b)]
|
||||
print(sum(distance))
|
||||
|
||||
# part 2
|
||||
from collections import Counter
|
||||
c = Counter(b)
|
||||
scores = [x*c[x] for x in a]
|
||||
print(sum(scores))
|
Loading…
Reference in New Issue