The carousel turns
transcript
A carousel holds stock in bays. It turns, so the ends touch. Most walks forget that. Then they count some blocks twice. Here is the fix, in one line.
One row: full, empty, full. The plain walk finds two blocks. But the last bay touches the first. The right answer is one block. The empty bay between them does not matter.
A flat grid takes column c plus one. A carousel takes the remainder by the width.
The wrap is one neighbour rule of three. Some problems add the four diagonals. Others compare the gap between two cells.
Left of column zero is minus one. Java and C plus plus keep the minus sign. So add the width before the remainder.
On one four by five grid, the wrap gives three blocks. Without it, the same grid gives five.
Write the neighbour rule first. Wrap with a remainder. Test a single row. Full breakdown in the lecture.