I started Advent of Code 2025. Here are some tips I’ve picked up.

My solving workflow Link to heading

  1. Read the problem twice - I often miss details on first read
  2. Work through the example by hand (pen and paper for complex ones)
  3. Write the naive solution first
  4. If it’s too slow, then optimise

I’ve wasted time optimising prematurely. Get it working, then make it fast.

Why Python? Link to heading

Python is great for AoC because:

  • Fast to write and iterate
  • Built-in data structures (lists, sets, dicts) cover most needs
  • collections and itertools are perfect for puzzles
  • Easy string manipulation

The downside: it’s slow. Some puzzles need optimisation or a smarter algorithm. I’ve never had to switch languages though.

Common patterns Link to heading

Read input from file:

with open("input.txt") as f:
    data = f.read().strip()

Split into lines:

lines = data.split("\n")

Parse numbers from lines:

numbers = [int(line) for line in lines]

Parse grid of characters:

grid = [list(line) for line in lines]

Parse pairs of numbers:

pairs = [tuple(map(int, line.split())) for line in lines]

Use collections.Counter for counting:

from collections import Counter
counts = Counter(items)

Use itertools for combinations:

from itertools import combinations, permutations
for a, b in combinations(items, 2):
    ...

Debugging Link to heading

Debug with print but comment out for speed:

# print(f"Step {i}: {state}")

For grid problems, visualise the grid:

def print_grid(grid):
    for row in grid:
        print("".join(row))

The key is to get a working solution first, then optimise if needed.

Further reading Link to heading