mirror of
https://github.com/thib8956/advent-of-code.git
synced 2025-07-01 22:35:47 +00:00
import 2024 aoc
This commit is contained in:
23
2024/day1/day1.py
Normal file
23
2024/day1/day1.py
Normal file
@ -0,0 +1,23 @@
|
||||
from collections import Counter
|
||||
|
||||
|
||||
def main(lines):
|
||||
firsts, seconds = list(sorted(x[0] for x in lines)), list(sorted(x[1] for x in lines))
|
||||
total = sum(abs(a - b) for (a, b) in zip(firsts, seconds))
|
||||
print("Part 1: ", total)
|
||||
|
||||
counts = Counter(seconds)
|
||||
total = sum(x * counts[x] for x in firsts)
|
||||
print("Part 2: ", total)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
import sys
|
||||
infile = sys.argv[1]
|
||||
|
||||
with open(infile) as f:
|
||||
lines = f.readlines()
|
||||
lines = [list(map(int, x.rstrip().split())) for x in lines]
|
||||
main(lines)
|
||||
|
1000
2024/day1/input.txt
Normal file
1000
2024/day1/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user