Last active
March 28, 2023 16:14
-
-
Save konarev/889b684d483f1b9306276141e0a9a402 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
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