Last active
December 1, 2024 15:05
Advent of Code 2024 https://adventofcode.com/2024/
This file contains 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
from sys import stdin | |
from operator import sub | |
input_data = [ (int(a),int(b)) for a,b in (line.split() for line in stdin)] | |
print( sum( map(lambda a: abs(sub(*a)), | |
zip(sorted(a for a,b in input_data), | |
sorted(b for a,b in input_data)) ))) |
This file contains 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
from sys import stdin | |
from collections import Counter | |
from math import sumprod | |
input_data = [ (int(a),int(b)) for a,b in (line.split() for line in stdin)] | |
counts = Counter( b for a,b in input_data ) | |
print(sumprod( (a for a,b in input_data), | |
(counts[a] for a,b in input_data))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment