Skip to content

Instantly share code, notes, and snippets.

@ozcan
Created August 31, 2016 22:56
Show Gist options
  • Save ozcan/6eca5bd1f050de9af2d6d723f642b81a to your computer and use it in GitHub Desktop.
Save ozcan/6eca5bd1f050de9af2d6d723f642b81a to your computer and use it in GitHub Desktop.
params = list(map(int, input().strip().split(" ")))
m, n, r = params[0], params[1], params[2]
matrix = []
outmatrix = []
for i in range(m):
matrix.append(list(map(int, input().strip().split(" "))))
outmatrix.append([0] * n)
output = ""
def find_new_pos(x, y, width, height, offset):
while (offset > 0):
if (x == 0):
y = y + offset
if (y >= height):
offset = y - height
y = height
else:
offset = 0
if (y == height):
x = x + offset
if (x >= width):
offset = x - width
x = width
else:
offset = 0
if (x == width):
y = y - offset
if (y <= 0):
offset = 0 - y
y = 0
else:
offset = 0
if (y == 0):
x = x - offset
if (x <= 0):
offset = 0 - x
x = 0
else:
offset = 0
return x, y
def print_matrix(matrix):
for row in matrix:
line = ""
for cell in row:
line += str(cell) + " "
print(line)
print("")
for layer in range(0, int(min(m,n) / 2)):
layer_height = m - (layer * 2)
layer_width = n - (layer * 2)
layer_perimeter = (2 * (layer_height + layer_width)) - 4
_r = r % layer_perimeter
for y in range(layer_height):
for x in range(layer_width):
if (x == 0 or x == layer_width -1 or y == 0 or y == layer_height -1):
newx, newy = find_new_pos(x, y, layer_width - 1, layer_height - 1, _r)
outmatrix[newy + layer][newx + layer] = matrix[layer + y][layer + x]
print_matrix(outmatrix)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment