day 1
This commit is contained in:
parent
02ba7c97f9
commit
f85cbb1539
1
day01/data.ivy
Normal file
1
day01/data.ivy
Normal file
File diff suppressed because one or more lines are too long
1000
day01/input
Normal file
1000
day01/input
Normal file
File diff suppressed because it is too large
Load Diff
6
day01/sample1.in
Normal file
6
day01/sample1.in
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
3 4
|
||||||
|
4 3
|
||||||
|
2 5
|
||||||
|
1 3
|
||||||
|
3 9
|
||||||
|
3 3
|
3
day01/sol.ivy
Normal file
3
day01/sol.ivy
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
) read "data.ivy"
|
||||||
|
|
||||||
|
a
|
18
day01/sol.py
Normal file
18
day01/sol.py
Normal file
@ -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…
x
Reference in New Issue
Block a user