Advertisement
EXTREMEXPLOIT

Hourglass Sum

Dec 30th, 2019
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. def hourglassSum(Array):
  2.     Rows = len(Array)
  3.     Columns = len(Array[0])
  4.     MAX = None
  5.     for i in range(Rows):
  6.         for j in range(Columns):
  7.             if j <= Columns/2 and i <= Rows/2:
  8.                 CurrentClock = []
  9.                 CurrentClock.append(Array[i][j])
  10.                 CurrentClock.append(Array[i][j+1])
  11.                 CurrentClock.append(Array[i][j+2])
  12.  
  13.                 CurrentClock.append(Array[i+1][j+1])
  14.  
  15.                 CurrentClock.append(Array[i+2][j])
  16.                 CurrentClock.append(Array[i+2][j+1])
  17.                 CurrentClock.append(Array[i+2][j+2])
  18.  
  19.                 if MAX == None or sum(CurrentClock) > MAX:
  20.                     print(sum(CurrentClock), ">", MAX)
  21.                     MAX = sum(CurrentClock)
  22.                     print(MAX)
  23.     return MAX
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement