Created
October 9, 2015 20:03
-
-
Save yoanisgil/cca365a69563dd58d6fc 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 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