Added day1

This commit is contained in:
Andreas 2024-12-03 08:56:03 +01:00 committed by Andreas
parent 806d41e51a
commit 6cf6f5bf02
3 changed files with 1068 additions and 0 deletions

1000
day1/input.txt Normal file

File diff suppressed because it is too large Load diff

34
day1/solution.py Normal file
View file

@ -0,0 +1,34 @@
example = """
3 4
4 3
2 5
1 3
3 9
3 3
"""
parsed = [[],[]]
for x in open('input.txt', 'r').readlines():
if x:
a = [y for y in x.split(" ") if y]
parsed[0].append(a[0])
parsed[1].append(a[1])
parsed[0] = sorted(parsed[0])
parsed[1] = sorted(parsed[1])
asd = []
for x, y in zip(parsed[0], parsed[1]):
x = int(x)
y = int(y)
if x > y:
asd.append(x-y)
else:
asd.append(y-x)
num = sum(asd)
print(num)

34
day1/solution2.py Normal file
View file

@ -0,0 +1,34 @@
example = """
3 4
4 3
2 5
1 3
3 9
3 3
"""
parsed = [[],[]]
for x in open('input.txt', 'r').readlines():
# for x in example.splitlines():
if x:
a = [y for y in x.split(" ") if y]
parsed[0].append(a[0])
parsed[1].append(a[1])
parsed[0] = sorted(parsed[0])
parsed[1] = sorted(parsed[1])
parsed[0] = [int(x) for x in parsed[0]]
parsed[1] = [int(x) for x in parsed[1]]
asd = []
for x in parsed[0]:
cnt = parsed[1].count(x)
asd.append(x*cnt)
num = sum(asd)
print(num)