AoC 2024 Day 1

This commit is contained in:
Felix Pankratz 2024-12-01 12:51:05 +01:00
parent 69419eef04
commit 15024dbdaf
2 changed files with 40 additions and 0 deletions

21
2024/01/01.py Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env python3
INPUT_FILE = 'input.txt'
def main():
left, right = [], []
contents = open(INPUT_FILE, 'r').readlines()
for line in contents:
fields = line.split(' ')
left.append(int(fields[0]))
right.append(int(fields[-1]))
left.sort()
right.sort()
diff_sum = 0
for pair in list(zip(left, right)):
diff_sum += abs(pair[0] - pair[1])
print(diff_sum)
if __name__ == '__main__':
main()

19
2024/01/02.py Executable file
View File

@ -0,0 +1,19 @@
#!/usr/bin/env python3
INPUT_FILE = 'input.txt'
def main():
left, right = [], []
contents = open(INPUT_FILE, 'r').readlines()
for line in contents:
fields = line.split(' ')
left.append(int(fields[0]))
right.append(int(fields[-1]))
similarity = 0
for id in left:
similarity += id * right.count(id)
print(similarity)
if __name__ == '__main__':
main()