python псевдокод :
def iterate_cells(n):
for i in range(n):
for j in range(i+1):
yield (j, i-j)
for i in range(1, n+1):
for j in range(n - i):
yield(i+j, n-j-1)
выход:
In [119]: list(iterate_cells(5))
Out[119]:
[(0, 0),
(0, 1),
(1, 0),
(0, 2),
(1, 1),
(2, 0),
(0, 3),
(1, 2),
(2, 1),
(3, 0),
(0, 4),
(1, 3),
(2, 2),
(3, 1),
(4, 0),
(1, 4),
(2, 3),
(3, 2),
(4, 1),
(2, 4),
(3, 3),
(4, 2),
(3, 4),
(4, 3),
(4, 4)]