Solve 2021 day 17

This commit is contained in:
2024-11-24 09:53:34 -05:00
parent bde0a5d622
commit ff3d33a614
2 changed files with 37 additions and 1 deletions

35
2021/d17.py Normal file
View File

@@ -0,0 +1,35 @@
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))