Hello, Kratos!

Given a grid of squares, where each square has an ID.

The first(top left) square has IDd 0 (so a 5x5 grid will have IDs 0-24) like below:

I need to generate all diagonal solutions of length Y. So if Y is 3, then some of the solutions will be:

and

but obviously NOT

Any ideas how these solutions can be generated?

We have an grid.

And we want diagonals of length

Across the top row, there are diagonals.

And there will be such rows.

Hence, there are diagonals of this form

. . and diagonals of this form

Therefore, there are: diagonals of length