Created
October 26, 2017 18:40
-
-
Save pavelpatrin/b6363e5aa9c69965f5f3c14144c4d221 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 matrix(side_width): | |
for y in xrange(side_width): | |
for x in xrange(side_width): | |
ring_number = min(x, y, side_width - 1 - x, side_width - 1 - y) | |
ring_serial = x + y - 2 * ring_number | |
if x >= y: | |
ring_base = 4 * ring_number * (side_width - ring_number) | |
result = ring_base + ring_serial | |
else: | |
ring_ceil = 4 * (ring_number + 1) * (side_width - ring_number - 1) | |
result = ring_ceil - ring_serial | |
sys.stdout.write('%6s' % (result + 1)) | |
sys.stdout.write('\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://habrahabr.ru/post/210796/