Created
December 1, 2024 21:07
-
-
Save object/8c025feeb889f6963fd160aa5b0d213e to your computer and use it in GitHub Desktop.
Advent of Code 2024, day 01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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