-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDay_5_2DArray.py
63 lines (48 loc) · 1.17 KB
/
Day_5_2DArray.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# https://www.hackerrank.com/challenges/2d-array/problem
#!/bin/python3
import math
import os
import random
import re
import sys
def Matmul(X):
# result is 3x4
cp = [1,1,1,0,1,0,1,1,1]
result = [[0,0,0],
[0,0,0],
[0,0,0]]
s = 0
for i in range(9):
s += X[i] * cp[i]
#print(result)
return s
# Complete the hourglassSum function below.
def hourglassSum(arr):
fina = []
for i in range(len(arr)-2):
sum = 0
temp = []
for j in range(len(arr)-2):
a = i
b = j
fi = []
s = []
while(a<i+3):
b = j
while(b<j+3):
fi.append(arr[a][b])
b+=1
#s.append(fi)
a+=1
#print(fi)
temp.append(Matmul(fi))
fina.append(temp)
return max(map(max, fina))
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()