• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Apr 23rd, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #!/bin/python3
2.
3. import math
4. import os
5. import random
6. import re
7. import sys
8.
9. # Complete the hourglassSum function below.
10. def hourglassSum(arr):
11.     if arr is None:
12.         return 0
13.     newrow = len(arr)-2
14.     newcol = len(arr[0])-2
15.     if newrow <= 0 or newcol <= 0:
16.         return 0
17.     hourglass = [[0 for col in range(newcol)] for row in range(newrow)]
18.     for row in range(len(hourglass)):
19.         for col in range(len(hourglass[0])):
20.             hourglass[row][col] = arr[row][col] + arr[row][col+1] + arr[row][col+2]
21.             hourglass[row][col] += arr[row+1][col+1]
22.             hourglass[row][col] += arr[row+2][col] + arr[row+2][col+1] + arr[row+2][col+2]
23.     maxValue = max(hourglass[0])
24.     for row in range(1,len(hourglass)):
25.         if maxValue < max(hourglass[row]):
26.             maxValue = max(hourglass[row])
27.     return maxValue
28.
29.
30. if __name__ == '__main__':
31.     fptr = open(os.environ['OUTPUT_PATH'], 'w')
32.
33.     arr = []
34.
35.     for _ in range(6):
36.         arr.append(list(map(int, input().rstrip().split())))
37.
38.     result = hourglassSum(arr)
39.
40.     fptr.write(str(result) + '\n')
41.
42.     fptr.close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top