Advent of Code Solver
Language-agnostic problem solving: TDD + correctness-first.
Workflow
1. READ → Study problem + examples (examples are your spec)
2. PARSE → Extract data structures from input
3. TEST → Write tests from example input/output
4. IMPLEMENT → Minimal code to pass
5. RUN → Execute on real input
6. ADAPT → Refactor for Part 2
Solution Architecture
parse(input) → data structure
part1(data) → answer
part2(data) → answer
Parse once; solve both parts; test each function independently.
Algorithm Selection
| Scenario |
Algorithm |
| Unweighted shortest path |
BFS |
| Path existence / exhaustive |
DFS |
| Weighted shortest path |
Dijkstra |
| Weighted + good heuristic |
A* |
| "After N iterations..." (huge N) |
Cycle detection |
| "Find minimum X such that..." |
Binary search |
| "Count ways..." / "Min/max..." |
Dynamic programming |
| Connected regions |
Flood fill |
Algorithms: algorithms.md
Input Patterns
| Format |
Approach |
| Numbers in text |
Regex -?\d+ |
| Grid of chars |
2D array or dict by coords |
| Blank-line groups |
Split on \n\n first |
| Key-value pairs |
Parse into map/dict |
| Instructions/opcodes |
Pattern match each line |
Grid coordinates: (row, col), row↓; sparse dict for infinite/sparse grids.
Directions: UP=(-1,0), DOWN=(1,0), LEFT=(0,-1), RIGHT=(0,1)
Parsing: parsing.md
Part 2 Patterns
- Scale up → Optimize algorithm
- Add dimensions → 2D → 3D/4D
- Many iterations → Find cycle, skip ahead
- Reverse question → "Find X" → "Given X, find Y"
- Add constraints → New rules or edge cases
Debugging
- Print intermediate state at each step
- Compare with example walkthrough
- Add assertions for every assumption
- Test parsing separately from logic
- Binary search on input size to isolate failures
Complexity Targets
| Input Size |
Target |
| n ≤ 20 |
O(2^n) OK |
| n ≤ 500 |
O(n³) OK |
| n ≤ 10,000 |
O(n²) OK |
| n ≤ 1,000,000 |
O(n log n) |
| n > 1,000,000 |
O(n) or O(log n) |
Research Tools
# gh search code for algorithm implementations
gh search code "heapq.heappush" --language=python # Dijkstra/priority queue
gh search code "collections.deque" --language=python # BFS patterns
gh search code "fn dijkstra" --language=rust
Required follow-up reads
| Need |
Read |
When |
| Algorithm recipes |
cookbook/algorithms.md |
When selecting or implementing graph, DP, cycle, or search algorithms |
| Parsing recipes |
cookbook/parsing.md |
For grids, grouped input, coordinates, hex grids, or irregular text |
| General design reference |
reference.md |
For data structures, optimization, Part 2 adaptation, or anti-patterns |
1---2name: aoc3description: Use for Advent of Code, algorithm puzzles, competitive programming, or puzzle-solution optimization.4license: AGPL-3.0-or-later5---67# Advent of Code Solver89Language-agnostic problem solving: TDD + correctness-first.1011## Workflow1213```141. READ → Study problem + examples (examples are your spec)152. PARSE → Extract data structures from input163. TEST → Write tests from example input/output174. IMPLEMENT → Minimal code to pass185. RUN → Execute on real input196. ADAPT → Refactor for Part 220```2122## Solution Architecture2324```25parse(input) → data structure26part1(data) → answer27part2(data) → answer28```2930Parse once; solve both parts; test each function independently.3132## Algorithm Selection3334|Scenario|Algorithm|35|---|---|36|Unweighted shortest path|BFS|37|Path existence / exhaustive|DFS|38|Weighted shortest path|Dijkstra|39|Weighted + good heuristic|A\*|40|"After N iterations..." (huge N)|Cycle detection|41|"Find minimum X such that..."|Binary search|42|"Count ways..." / "Min/max..."|Dynamic programming|43|Connected regions|Flood fill|4445Algorithms: [algorithms.md](cookbook/algorithms.md)4647## Input Patterns4849|Format|Approach|50|---|---|51|Numbers in text|Regex `-?\d+`|52|Grid of chars|2D array or dict by coords|53|Blank-line groups|Split on `\n\n` first|54|Key-value pairs|Parse into map/dict|55|Instructions/opcodes|Pattern match each line|5657Grid coordinates: `(row, col)`, row↓; sparse dict for infinite/sparse grids.58Directions: `UP=(-1,0), DOWN=(1,0), LEFT=(0,-1), RIGHT=(0,1)`5960Parsing: [parsing.md](cookbook/parsing.md)6162## Part 2 Patterns63641. **Scale up** → Optimize algorithm652. **Add dimensions** → 2D → 3D/4D663. **Many iterations** → Find cycle, skip ahead674. **Reverse question** → "Find X" → "Given X, find Y"685. **Add constraints** → New rules or edge cases6970## Debugging7172- Print intermediate state at each step73- Compare with example walkthrough74- Add assertions for every assumption75- Test parsing separately from logic76- Binary search on input size to isolate failures7778## Complexity Targets7980|Input Size|Target|81|---|---|82|n ≤ 20|O(2^n) OK|83|n ≤ 500|O(n³) OK|84|n ≤ 10,000|O(n²) OK|85|n ≤ 1,000,000|O(n log n)|86|n > 1,000,000|O(n) or O(log n)|8788## Research Tools8990```91# gh search code for algorithm implementations92gh search code "heapq.heappush" --language=python # Dijkstra/priority queue93gh search code "collections.deque" --language=python # BFS patterns94gh search code "fn dijkstra" --language=rust95```9697## Required follow-up reads9899|Need|Read|When|100|---|---|---|101|Algorithm recipes|`cookbook/algorithms.md`|When selecting or implementing graph, DP, cycle, or search algorithms|102|Parsing recipes|`cookbook/parsing.md`|For grids, grouped input, coordinates, hex grids, or irregular text|103|General design reference|`reference.md`|For data structures, optimization, Part 2 adaptation, or anti-patterns|