Skip to content

Commit 0e369c6

Browse files
committed
Add day 17
1 parent 76abb9f commit 0e369c6

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed

2021/17/17.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
x1, x2, y1, y2 = [parse(Int, m.match) for m in eachmatch(r"-?\d+", readline())]
2+
count = 0
3+
function simulate(yspeed, xspeed)
4+
x, y, maxy = 0, 0, 0
5+
while x <= x2 && y >= y1
6+
y, x = y + (yspeed -= 1), x + (xspeed -= xspeed > 0)
7+
maxy = max(y, maxy)
8+
x x1:x2 && y y1:y2 && (global count += 1) > 0 && return maxy
9+
end
10+
return 0
11+
end
12+
maximum(simulate(ys, xs) for ys=y1:200, xs=1:x2+1) |> m -> println("$m\n$count")

2021/17/example.ans

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
45
2+
112

2021/17/example.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target area: x=20..30, y=-10..-5

2021/17/input.ans

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
10296
2+
2371

2021/17/input.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target area: x=96..125, y=-144..-98

0 commit comments

Comments
 (0)