Python Day 11: 2D Arrays




Given a 6x6 2D Array, A:

Calculate the hourglass sum for every hourglass in A, then print the maximum hourglass sum.



  1. #!/bin/python3
  2. import math
  3. import os
  4. import random
  5. import re
  6. import sys
  7. if __name__ == '__main__':
  8. arr = []
  9. for _ in range(6):
  10. tmp = [int(x) for x in str(input()).split(" ")]
  11. arr.append(tmp)
  12. maximum = -9 * 7
  13. for i in range(6):
  14. for j in range(6):
  15. if j + 2 < 6 and i + 2 < 6:
  16. result = arr[i][j] + arr[i][j + 1] + arr[i][j + 2] + arr[i + 1][j + 1] + arr[i + 2][j] + arr[i + 2][j + 1] + arr[i + 2][j + 2]
  17. if result > maximum:
  18. maximum = result
  19. print(maximum)
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]


donate a cup of tea :)


Join Our Facebook Group

Share this solution






codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube