16/28
Part 4 of 6 · Rows and columnsLearn and do

One set per column

Under the grid rule, one shown set for the page is the wrong memory. A title blocks only its own column, so keep one set per column:

from collections import defaultdict

# slot j -> titles in column j so far
columns = defaultdict(set)

A slot j takes the row's best title that passes two checks:

  • not in this row's head already, the row rule
  • not in columns[j], the column rule

When a title is placed in slot j, it goes into columns[j] and nowhere else.

Predict

Columns so far: column 0 holds A, column 1 holds B. The row is A, B, C, width 2. What does it show?

Pick an answer above to see the rest