2024 Day 1

This commit is contained in:
Walter Bolles 2024-12-05 10:52:29 -05:00
parent d166a5fcb3
commit 51716d0275
Signed by: wjbolles
GPG key ID: E2633AE96FD07002
3 changed files with 1037 additions and 0 deletions

6
python/day1-sample.txt Normal file
View file

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

31
python/day1.py Normal file
View file

@ -0,0 +1,31 @@
with open('day1.txt') as f:
lines = f.read().splitlines()
print("Day 1 Part 1:")
a = []
b = []
for line in lines:
x,y = line.split()
a.append(int(x))
b.append(int(y))
a.sort()
b.sort()
sum = 0
for x, y in zip(a, b):
sum += abs(x-y)
print("sum: " + str(sum))
print("Day 1 Part 2")
sum2 = 0
for x in a:
sum2 += x * b.count(x)
print("sum2: " + str(sum2))

1000
python/day1.txt Normal file

File diff suppressed because it is too large Load diff