Created
February 2, 2020 22:16
-
-
Save dmitryTsatsarin/4c0b3f133359b4277e8fac050537ff68 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import sys | |
def snail(n, m): | |
dx, dy = 1, 0 | |
x, y = 0, 0 | |
arr = [[0] * m for _ in range(n)] | |
for i in range(1, n * m + 1): | |
print(y, x) | |
arr[x][y] = i | |
new_x, new_y = x + dx, y + dy | |
if 0 <= new_x < n and 0 <= new_y < m and not arr[new_x][new_y]: | |
x, y = new_x, new_y | |
else: | |
dx, dy = -dy, dx | |
x, y = x + dx, y + dy | |
n = int(sys.argv[1]) | |
m = int(sys.argv[2]) | |
snail(n, m) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment