Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement