main
magical 2024-12-02 03:40:57 +00:00
parent 02ba7c97f9
commit f85cbb1539
5 changed files with 1028 additions and 0 deletions

1
day01/data.ivy 100644

File diff suppressed because one or more lines are too long

1000
day01/input 100644

File diff suppressed because it is too large Load Diff

6
day01/sample1.in 100644
View File

@ -0,0 +1,6 @@
3 4
4 3
2 5
1 3
3 9
3 3

3
day01/sol.ivy 100644
View File

@ -0,0 +1,3 @@
) read "data.ivy"
a

18
day01/sol.py 100644
View 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))