Skip to content

Instantly share code, notes, and snippets.

@itayzit
Created December 13, 2021 00:10
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/b6c24fa7dc0c4f8c5318a0707f6d1136 to your computer and use it in GitHub Desktop.
Save itayzit/b6c24fa7dc0c4f8c5318a0707f6d1136 to your computer and use it in GitHub Desktop.
# Part 1 solution
import gamla
with open(filename, "r") as f:
result = gamla.pipe(
f.readlines(),
gamla.map(str.strip),
gamla.map(gamla.split_text(" ")),
gamla.bifurcate(
gamla.filter(gamla.inside("forward")),
gamla.filter(gamla.inside("down")),
gamla.filter(gamla.inside("up")),
),
gamla.map(gamla.map(gamla.compose_left(gamla.second, int))),
gamla.map(sum),
list,
gamla.star(lambda forward, down, up: forward * (down - up)),
)
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment