3 × 4 grid
1
2
3
4
5
6
7
8
9
10
11
12
spiral order
Boundary simulation
▸1top=0, bottom=R−1, left=0, right=C−12while top ≤ bottom and left ≤ right:34 for c in left..right: take (top, c)5 top++6 for r in top..bottom: take (r, right)7 right−−8 if top ≤ bottom:9 for c in right..left: take (bottom, c)10 bottom−−11 if left ≤ right:12 for r in bottom..top: take (r, left)13 left++14return collected
state
- rows3
- cols4