Advertisement
hhoppe

Advent of code 2024 day 1

Nov 30th, 2024 (edited)
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.28 KB | None | 0 0
  1. def day1(s, *, part2=False):
  2.   columns = np.array([line.split() for line in s.splitlines()], int).T
  3.  
  4.   if not part2:
  5.     return abs(np.diff(np.sort(columns), axis=0)).sum()
  6.  
  7.   counts = collections.Counter(columns[1])
  8.   return sum(value * counts[value] for value in columns[0])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement