AoC 2024 Day 1
This commit is contained in:
parent
69419eef04
commit
15024dbdaf
21
2024/01/01.py
Executable file
21
2024/01/01.py
Executable 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
19
2024/01/02.py
Executable 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()
|
Loading…
Reference in New Issue
Block a user