At Boston Python last night, I did a presentation about solutions to a particular Advent of Code puzzle.
The presentation took a particular Advent of Code puzzle (December 14, 2016) and explained out a few different solutions, with a small detour into unit testing.
The code shows a few different ways to deal with the problem:
- a simple implementation for part 1
- a global cache dictionary
- a local cache dictionary in a closure
- a cache decorator, similar to the @lru_cache decorator in the standard library
- finally, a PeekableIterable class to use more pure iteration
During the talk, an audience member suggested that itertools.tee could be useful, which I hadn’t considered. So I tried that out also, though it wasn’t as nice as I had hoped, and maybe is holding on to too much state.
Sorry I didn’t write out the text of the talk itself...