Algorithms & Theory Reference
The Advent of Code Book
Every December since 2015, Advent of Code has invited programmers to solve a new puzzle each day. A quick script can often earn a star, yet the real reward comes when a messy story clicks into a clean idea from computer science.
Algorithms make sense when you see them solve real problems. Each chapter takes a puzzle from its raw input to the mathematics underneath, showing why an optimal method works and where its limits lie. You learn to recognize the patterns behind graphs, dynamic programming, and number theory—so you can walk into Advent of Code ready to solve puzzles on your own.
Start with the problem model, follow the program steps and block diagrams, and test your own ideas before opening the hidden solution.
Structure of Each Chapter
Every puzzle chapter follows the same layout so you can focus on the ideas instead of the format:
- Puzzle Excerpt & Problem Model — Read the exact rules from the puzzle. Inspect the input format with a small example, then translate it into a formal mathematical model.
- Separate Part 1 and Part 2 — Study each part on its own. Part 2 often changes the constraints and requires a different algorithm.
- Algorithmic Theory & Side Notes — Learn the name, origin, and theory behind each method, with Wikipedia references. Plain-English side notes explain difficult academic terms in simple words.
- Complexity Analysis — Review the time and space bounds, including best and worst cases, to see why the method scales.
- Program Steps & Block Diagrams — Follow a numbered step-by-step algorithm and a visual flowchart before you look at any source code.
- Hidden Multi-Language Code — Keep code collapsed by default so you can attempt the puzzle first. When ready, compare clean implementations across 10 languages: C, Clojure, Go, Haskell, Java, JavaScript, Lua, Python, Ruby, and Rust.
Chapters by Year
Where it all began — classic algorithmic foundations
Easter Bunny HQ
Printer & Memory Puzzles
Chronal Calibration
The Intcode Odyssey
Tropical Vacation
Submarine Expedition
Jungle Expedition
Snow Island Restoration
Chief Historian Search
North Pole Workshop