Skip to content

Instantly share code, notes, and snippets.

@bioinfornatics
Created June 4, 2015 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bioinfornatics/b84da92488ef55453f0a to your computer and use it in GitHub Desktop.
Save bioinfornatics/b84da92488ef55453f0a to your computer and use it in GitHub Desktop.
#!/usrbin/env python
def getMaxRowLength( matrix ):
maxLen = 0
for i in matrix:
if len(i) > maxLen:
maxLen = len(i)
return maxLen
def computeDiag( matrix, i , j ):
result = matrix[i][j]
isComputing = True
while isComputing:
j -= 1
i += 1
if j < 0:
isComputing = False
elif i < len(matrix) and j < len( matrix[i] ):
result += matrix[i][j]
return result
if __name__ == "__main__":
matrix = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 8, 7, 3] ]
counter = 0
rowIndex = 0
colIndex = 0
result = []
maxLen = getMaxRowLength( matrix )
for colIndex in range( 0, maxLen ):
result.append( computeDiag( matrix, rowIndex , colIndex ) )
rowIndex += 1
for rowIndex in range( rowIndex, len( matrix ) ):
result.append( computeDiag( matrix, rowIndex , colIndex ) )
print result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment