Last active
May 30, 2022 08:07
-
-
Save Mu-adventofcode/72bca9f2194e8b3df720d754df915eb2 to your computer and use it in GitHub Desktop.
AoC day 17 part 1 simple
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
inp = open("input_17.txt").read().strip() | |
xmin, xmax, ymin, ymax = map(int, re.findall(r"([+-]?\d+)", inp)) | |
gtop = 0 | |
for (vx, vy) in ( | |
(a, b) | |
for a in range(1, xmax + 1) | |
for b in range(ymin, abs(ymin)) | |
): | |
x = y = ltop = 0 | |
while True: | |
x, vx = x + vx, vx - bool(vx) | |
y, vy = y + vy, vy - 1 | |
ltop = max(ltop, y) | |
if x > xmax or y < ymin: | |
break | |
elif xmin <= x <= xmax and ymin <= y <= ymax: | |
gtop = max(gtop, ltop) | |
print(gtop) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment