Untitled
unknown
python
4 years ago
1.1 kB
59
Indexable
import sys
def read_input():
line = sys.stdin.read()[13:]
x, y = line.split(', ')
xl, xh = x[2:].split('..')
yl, yh = y[2:].split('..')
return int(xl), int(xh), int(yl), int(yh)
def calc_y_steps(y_vel, yl, yh):
steps = []
y_pos = 0
s = 0
while y_pos >= yl:
y_pos += y_vel
s += 1
y_vel -= 1
if yl <= y_pos <= yh:
steps.append(s)
return steps
def calc_x_with_y(steps, xl, xh):
x_vels_with_steps = set()
for step in steps:
for x_vel in range(0, xh+1):
x_pos = sum(x_vel - s for s in range(step) if s <= x_vel)
if xl <= x_pos <= xh:
x_vels_with_steps.add(x_vel)
return x_vels_with_steps
def solve():
xl, xh, yl, yh = read_input()
count = 0
for y_vel in range(-1000, 1000):
steps = calc_y_steps(y_vel, yl, yh)
x_vels_with_steps = calc_x_with_y(steps, xl, xh)
count += len(x_vels_with_steps)
print(count)
solve()Editor is loading...