Functional Python: Saving Christmas with itertools & friends
summary
Uses itertools.pairwise() to replace nested neighbor loops (computes adjacent differences), uses itertools.product() to enumerate 2^(k-1) operator combinations for the bridge-repair puzzle, and uses functools.reduce() plus operator.add to fold column-major bits into a binary string. Shows zip(*) transposition for 2021 Day 3, notes more-itertools for windowed/chunked helpers, and demonstrates that a mutable, imperative class is necessary for the disk-compaction puzzle where purely functional copies blow up memory and performance.
AI-written summary · about
chapters (21)
- 0:00Introduction
- 1:10Why functional Python
- 3:17Brute force vs functional
- 4:42Functional principles
- 6:27Pure functions example
- 8:15Higher-order functions
- 9:18Iterators and generators
- 11:50Built-in functional tools
- 13:17Advent of Code patterns
- 15:26Neighbors with pairwise
- 16:30Combinations with product
- 18:22Operator module demo
- 20:26Combinatorics tools
- 20:49Aggregation and reduction
- 21:31Transposing with zip
- 24:26Reducing to single value
- 25:33When functional fails
- 27:19Mutable state example
- 28:45Right tool for the job
- 29:05Key takeaways
- 29:50Resources and closing
