From a1ba33d7e8ab5b9788c0a787fa767ff16e6497ac Mon Sep 17 00:00:00 2001 From: dece Date: Fri, 17 Dec 2021 16:12:44 +0100 Subject: [PATCH] Day 17 --- 2021/day17.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 2021/day17.py diff --git a/2021/day17.py b/2021/day17.py new file mode 100644 index 0000000..ed0bb06 --- /dev/null +++ b/2021/day17.py @@ -0,0 +1,28 @@ +with open("input17.txt") as f: + line = f.read().rstrip() +(xmin, xmax), (ymin, ymax) = ( + tuple(map(int, part.rstrip(",")[2:].split(".."))) + for part in line.split()[2:] +) + +# highest y regardless of x will be the one using the velocity that immediately +# goes to ymin after crossing the 0 axis... +print(sum(range(abs(ymin + 1) + 1))) + +n = 0 +ivxmax = abs(xmax) +ivymax = abs(xmax) +for ivx in range(ivxmax, -1, -1): + for ivy in range(ivymax, -ivymax - 1, -1): + x, y = 0, 0 + vx, vy = ivx, ivy + while x <= xmax and y >= ymin: + x += vx + y += vy + if vx > 0: + vx -= 1 + vy -= 1 + if xmin <= x <= xmax and ymin <= y <= ymax: + n += 1 + break +print(n)