def largest_product_of_series(length): largest_product = 0 coord_x = coord_y = -1 for y in xrange(HEIGHT): for x in xrange(WIDTH): is_in_bounds_right = x + length < WIDTH + 1 is_in_bounds_bottom = y + length < HEIGHT + 1 is_in_bounds_left = x > length # Right if is_in_bounds_right: s = product(GRID[y][x:x + length]) if s > largest_product: largest_product = s coord_x, coord_y = x, y # Down if is_in_bounds_bottom: s = product([GRID[y + i][x] for i in xrange(length)]) if s > largest_product: largest_product = s coord_x, coord_y = x, y # Diagonal down right if is_in_bounds_right and is_in_bounds_bottom: s = product([GRID[y + i][x + i] for i in xrange(length)]) if s > largest_product: largest_product = s coord_x, coord_y = x, y # Diagonal down left if is_in_bounds_left and is_in_bounds_bottom: s = product([GRID[y + i][x - i] for i in xrange(length)]) if s > largest_product: largest_product = s coord_x, coord_y = x, y # Y, X, PRODUCT return Result(coord_x, coord_y, largest_product)
def least_common_multiple(nums): return product(collect_factors(nums))
def test(self): assert product(triplet(3 + 4 + 5)) == 3 * 4 * 5
def run(self): return product(triplet(TARGET, search_delta=TARGET))
def triplet_product(n): return product(triplet(n))
def product_of_digits(digits): return product(map(int, digits))