Skip to content

Instantly share code, notes, and snippets.

@object
Created December 1, 2024 21:07
Show Gist options
  • Save object/8c025feeb889f6963fd160aa5b0d213e to your computer and use it in GitHub Desktop.
Save object/8c025feeb889f6963fd160aa5b0d213e to your computer and use it in GitHub Desktop.
Advent of Code 2024, day 01
import re
with open("./data/input01.txt") as inputFile:
input = inputFile.read().splitlines()
left = []
right = []
for line in input:
m = re.findall(r'(\d+)', line)
left.append(int(m[0]))
right.append(int(m[1]))
# Part 1: 2970687
res = 0
left.sort()
right.sort()
for i in range(len(left)):
res += abs(left[i] - right[i])
print(res)
# Part 2: 23963899
res = 0
for n in left:
res += n * len(list(filter(lambda x: x == n, right)))
print(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment