Skip to content

Instantly share code, notes, and snippets.

@itayzit
Created December 11, 2021 00:05
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 itayzit/710e6d65ca4c886ac81725a23d4df1a0 to your computer and use it in GitHub Desktop.
Save itayzit/710e6d65ca4c886ac81725a23d4df1a0 to your computer and use it in GitHub Desktop.
# A solution to both parts of AoC challenge day 1.
import gamla
PART = 1
with open(filename, "r") as f:
result = gamla.pipe(
f.readlines(),
gamla.map(int),
gamla.sliding_window(1 if PART == 1 else 3),
gamla.map(sum),
gamla.sliding_window(2),
gamla.reduce(lambda sum_so_far, window: sum_so_far + int(window[1] > window[0]), 0),
)
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment