6/40
Part 1 of 7 · Four thingsLearn and do
Any order works if every cell's inputs come first
Every order that works has one thing in common.
The cells and the arrows between them form a graph with no cycles, the kind the topological-sort lesson put in order. A fill order is correct when it is a topological order of that graph: every arrow points forward. Here are three orders:
| Order | Starts with | Gives |
|---|---|---|
| row by row | (0,0) (0,1) (0,2) (0,3) (1,0) | 26 |
| column by column | (0,0) (1,0) (2,0) (0,1) (1,1) | 26 |
| bottom row first | (2,0) (2,1) (2,2) (2,3) (1,0) | wrong: (2,0) reads (1,0), not filled yet |
Row by row and column by column both return 26. The fourth item, the order, is the one people skip. The base cases are the other half of it: they are the cells whose inputs don't exist, and you fill them before anything reads them.
In the editor, write points_to_corner(grid): the most points from each cell to the corner. Its inputs sit below and to the right, so its order runs the other way. It prints the table.