Skip to content

Instantly share code, notes, and snippets.

@Mu-adventofcode
Last active May 30, 2022 08:07
Show Gist options
  • Save Mu-adventofcode/72bca9f2194e8b3df720d754df915eb2 to your computer and use it in GitHub Desktop.
Save Mu-adventofcode/72bca9f2194e8b3df720d754df915eb2 to your computer and use it in GitHub Desktop.
AoC day 17 part 1 simple
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