Skip to content

Instantly share code, notes, and snippets.

@yoanisgil
Created October 9, 2015 20:03
Show Gist options
  • Save yoanisgil/cca365a69563dd58d6fc to your computer and use it in GitHub Desktop.
Save yoanisgil/cca365a69563dd58d6fc to your computer and use it in GitHub Desktop.
def update_ring(ring_number, matrix):
for i, row in enumerate(matrix):
for j, value in enumerate(row):
if value == 0 and (i in [ring_number, len(row) - ring_number - 1] or j in [ring_number, len(row) - ring_number - 1]):
matrix[i][j] = ring_number + 1
def pyramidMatrix(N):
matrix = []
for i in range(N):
matrix.append([0]*N)
for i in range(N/2 + 1):
update_ring(i, matrix)
return matrix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment