Wednesday 19 December 2018 — This is almost six years old. Be careful.
At Boston Python last night, I did a presentation about solutions to a particular Advent of Code puzzle.
If you haven’t seen Advent of Code, give it a look. A new puzzle each day in December until Christmas. This is the fourth year running, and you can go back and look at the past years (and days).
My presentation landing page has links to the slides and the code.
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...
Comments
Add a comment: