Created
May 22, 2015 22:54
-
-
Save mtth/8793f8f773fba82d94c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def indices(m, n): | |
"""Index generator to visit a 2-dimensional matrix in increasing i + j. | |
:param m: Number of rows. | |
:param n: Number of columns. | |
""" | |
for i in range(m): | |
for j in range(min(n, i + 1)): | |
yield (i - j, j) | |
for j in range(1, n): | |
for i in range(m - 1, max(-1, m + j - n - 1), -1): | |
yield (i, m - 1 - i + j) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment