from lib import get_data from lib import ints data = get_data(__file__) x_min, x_max, y_min, y_max = ints(data) def simulate(x, y, vx, vy): height_max = 0 while x <= x_max and y >= y_min: height_max = max(y, height_max) if x_min <= x <= x_max and y_min <= y <= y_max: return True, height_max x += vx y += vy if vx != 0: vx = vx - 1 if vx > 0 else vx + 1 vy -= 1 return False, 0 height_max = 0 total = set() for vx in range(1, 2000): for vy in range(-2000, 2000): in_target, height = simulate(0, 0, vx, vy) if in_target: total.add((vx, vy)) if in_target and height > height_max: height_max = height print(height_max) print(len(total))