14/32
Part 3 of 7 · Fewest stepsLearn and do
Count a minute only if its pass found something, then check that everything was reached
The infection question counts minutes, and an off-by-one is easy here.
forest minute 0F....minute 1FF...minute 2FFF..minute 3FFFF.minute 4FFFFF
Each pass finds one new tree, until minute 4's pass finds nothing: there is no minute 5.
When the question is how long until everything is reached, two details decide whether the count is right:
- Count a round only if it reached something. The pass over the last level finds nothing new. Counting it is off by one.
- Check that everything was reached. An empty queue means the search is over, not that it covered the grid, as the yard's fenced-off strip showed. Compare what you reached with what had to be reached.
In the editor, finish minutes_from(grid, start) with both rules: the minutes until every tree burns from one fire at start, or -1 if some tree never catches. trees counts the trees to reach.