def main(): grid = [list(map(int, line.split())) for line in numbers.split('\n')] best = 0 N = 20 for r in range(N): for c in range(N): # across if c + 4 < N: test = product(grid[r][c+i] for i in range(4)) if test > best: best = test # down if r + 4 < N: test = product(grid[r+i][c] for i in range(4)) if test > best: best = test # diagonal UL-DR if r + 4 < N and c + 4 < N: test = product(grid[r+i][c+i] for i in range(4)) if test > best: best = test # diagonal UR-DL if r + 4 < N and c-4 >= 0: test = product(grid[r+i][c-i] for i in range(4)) if test > best: best = test return best
def main(): best = 0 for i in range(len(digs)-13): prod = product(digs[i:i+13]) if prod > best: best = prod return best
def test_product(self): self.assertEqual(funcs.product(3, 5), 15)
end_row = row + row_d * 3 if end_row < 0 or end_row >= len(grid): continue for col_d in [-1,0,1]: if row_d == col_d == 0: continue end_col = col + col_d * 3 if end_col < 0 or end_col >= len(grid[row]): continue line = [] for i in range(4): line.append( (row + row_d*i, col + col_d*i ) ) yield line def sliceline(grid,line): sl = [] for p in line: yield grid[p[0]][p[1]] max_prod = 0 for r in range(len(grid)): for c in range(len(grid[r])): for ln in lines(r,c): ln_prod = product(sliceline(grid,ln)) if ln_prod > max_prod: max_prod = ln_prod print "{0},{1} = {2}".format(r,c,max_prod)