Skip to content

Instantly share code, notes, and snippets.

@haakonvt
Created December 9, 2023 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haakonvt/46b109aa6b36af8801a7d39550195b23 to your computer and use it in GitHub Desktop.
Save haakonvt/46b109aa6b36af8801a7d39550195b23 to your computer and use it in GitHub Desktop.
AOC 2023, day 9
def diff_inplace(arr):
for idx in range(arr.shape[1], 2, -1):
arr[:,:idx-1] = np.diff(arr[:,:idx])
return arr.sum()
p1 = np.array([l.split() for l in inp.splitlines()], dtype=np.int32)
p2 = np.fliplr(p1.copy())
print(diff_inplace(p1), diff_inplace(p2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment