Last active
December 1, 2024 15:05
-
-
Save markjenkins/603583015991210d891d4f7fc6d8127a to your computer and use it in GitHub Desktop.
Advent of Code 2024 https://adventofcode.com/2024/
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
| 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 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
| 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