Created
December 1, 2024 16:24
-
-
Save rodrigogiraoserrao/734b3dfa0d01478531be2f53fe203a01 to your computer and use it in GitHub Desktop.
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
| # === Parsing === | |
| left = [] | |
| right = [] | |
| with open("input.txt") as f: | |
| for line in f: | |
| l, r = map(int, line.split()) | |
| left.append(l) | |
| right.append(r) | |
| # === Part 1 === | |
| print( | |
| sum( | |
| abs(l - r) | |
| for l, r in zip(sorted(left), sorted(right)) | |
| ) | |
| ) | |
| # === Part 2 === | |
| from collections import Counter | |
| counts = Counter(right) | |
| similarity = 0 | |
| for number in left: | |
| similarity += number * counts[number] | |
| print(similarity) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment