diff --git a/2021/d17.py b/2021/d17.py new file mode 100644 index 0000000..4e9b2e6 --- /dev/null +++ b/2021/d17.py @@ -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)) diff --git a/README.md b/README.md index 0ab955a..fecf1cd 100644 --- a/README.md +++ b/README.md @@ -188,7 +188,8 @@ Solutions and utility script for Advent of Code challenges in Python. - Day 14: 25:52 (Not hard but just too slow.) - Day 15: 19:17 (Not that bad. Multiplying the thing threw me off.) - Day 16: 50:01 (Way too slow. Was non-trivial but fun. Much better was feasible.) -- Day 17: +- Day 17: 21:59 (Not tricky again but struggling for no reason.) +- Day 18: ## AoC 2022