""" grid_search.py """ grid = [ [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6] ] width = len(grid[0]) height = len(grid) big_result = 0 for row in range(width): for col in range(height): # (row, col) is starting point # loop over >> V . . # V . . for (row_offset, col_offset) in ((0,1), (1,0), (1,1), (1,-1)): result = 1 r = row c = col for which in range(4): try: result = result * grid[r][c] except: result = 0 r = r + row_offset c = c + col_offset if result > big_result: big_result = result