1 #!/usr/bin/env python 2 3 def find_the_max(ary): 4 max_val = 0 5 for i in range(len(ary)-1): 6 for j in range(len(ary[i])-1): 7 sum_val = ary[i][j] + ary[i+1][j] + ary[i][j+1] + ary[i+1][j+1] 8 if sum_val > max_val: 9 max_val = sum_val 10 return max_val 11 12 def find_the_max1(ary): 13 max_val = 0 14 lastsum_val = ary[0][0] + ary[1][0] 15 for i in range(len(ary)-1): 16 for j in range(1,len(ary[i])): 17 sum_val = lastsum_val 18 lastsum_val = ary[i][j] + ary[i+1][j] 19 sum_val += lastsum_val 20 if sum_val > max_val: 21 max_val = sum_val 22 return max_val 23 24 if __name__=="__main__": 25 ary = [[1,2,0,3,4],[2,3,4,5,1],[1,10,5,3,0]] 26 print(find_the_max(ary)) 27 print(find_the_max1(ary))