Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/python3
- import math
- import os
- import random
- import re
- import sys
- # Complete the hourglassSum function below.
- def hourglassSum(arr):
- if arr is None:
- return 0
- newrow = len(arr)-2
- newcol = len(arr[0])-2
- if newrow <= 0 or newcol <= 0:
- return 0
- hourglass = [[0 for col in range(newcol)] for row in range(newrow)]
- for row in range(len(hourglass)):
- for col in range(len(hourglass[0])):
- hourglass[row][col] = arr[row][col] + arr[row][col+1] + arr[row][col+2]
- hourglass[row][col] += arr[row+1][col+1]
- hourglass[row][col] += arr[row+2][col] + arr[row+2][col+1] + arr[row+2][col+2]
- maxValue = max(hourglass[0])
- for row in range(1,len(hourglass)):
- if maxValue < max(hourglass[row]):
- maxValue = max(hourglass[row])
- return maxValue
- if __name__ == '__main__':
- fptr = open(os.environ['OUTPUT_PATH'], 'w')
- arr = []
- for _ in range(6):
- arr.append(list(map(int, input().rstrip().split())))
- result = hourglassSum(arr)
- fptr.write(str(result) + '\n')
- fptr.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement