Skip to content

Instantly share code, notes, and snippets.

@dmitryTsatsarin
Created February 2, 2020 22:16
Show Gist options
  • Save dmitryTsatsarin/4c0b3f133359b4277e8fac050537ff68 to your computer and use it in GitHub Desktop.
Save dmitryTsatsarin/4c0b3f133359b4277e8fac050537ff68 to your computer and use it in GitHub Desktop.
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