Skip to content

Instantly share code, notes, and snippets.

@konarev
Last active March 28, 2023 16:14
Show Gist options
  • Save konarev/889b684d483f1b9306276141e0a9a402 to your computer and use it in GitHub Desktop.
Save konarev/889b684d483f1b9306276141e0a9a402 to your computer and use it in GitHub Desktop.
from itertools import count
N = 5
i = count(1)
numbers = {}
row = start_row = 1
colon = start_col = 1
for size in range(N, 0, -1):
for colon in range(start_col, size + 1):
numbers[(row, colon)] = next(i)
for row in range(start_row + 1, size + 1):
numbers[(row, colon)] = next(i)
for colon in range(size - 1, start_col - 1, -1):
numbers[(row, colon)] = next(i)
for row in range(size - 1, start_row, -1):
numbers[(row, colon)] = next(i)
row = start_row = start_row + 1
colon = start_col = start_col + 1
for row in range(1, N + 1):
for colon in range(1, N + 1):
print(f"{numbers[(row, colon)]:4}", end=" ")
print("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment