1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
--- Day 17: Trick Shot ---
You finally decode the Elves' message. HI, the message says. You continue searching for the sleigh
keys.
Ahead of you is what appears to be a large ocean trench. Could the keys have fallen into it? You'd
better send a probe to investigate.
The probe launcher on your submarine can fire the probe with any integer velocity in the x (forward)
and y (upward, or downward if negative) directions. For example, an initial x,y velocity like 0,10
would fire the probe straight up, while an initial velocity like 10,-1 would fire the probe forward
at a slight downward angle.
The probe's x,y position starts at 0,0. Then, it will follow some trajectory by moving in
[1m[97msteps[0m. On each step, these changes occur in the following order:
- The probe's x position increases by its x velocity.
- The probe's y position increases by its y velocity.
- Due to drag, the probe's x velocity changes by 1 toward the value 0; that is, it decreases by 1
if it is greater than 0, increases by 1 if it is less than 0, or does not change if it is already 0.
- Due to gravity, the probe's y velocity decreases by 1.
For the probe to successfully make it into the trench, the probe must be on some trajectory that
causes it to be within a [1m[97mtarget area[0m after any step. The submarine computer has already calculated
this target area (your puzzle input). For example:
target area: x=20..30, y=-10..-5
This target area means that you need to find initial x,y velocity values such that after any step,
the probe's x position is at least 20 and at most 30, [1m[97mand[0m the probe's y position is at least -10 and
at most -5.
Given this target area, one initial velocity that causes the probe to be within the target area
after any step is 7,2:
.............#....#............
.......#..............#........
...............................
S........................#.....
...............................
...............................
...........................#...
...............................
....................TTTTTTTTTTT
....................TTTTTTTTTTT
....................TTTTTTTT#TT
....................TTTTTTTTTTT
....................TTTTTTTTTTT
....................TTTTTTTTTTT
In this diagram, S is the probe's initial position, 0,0. The x coordinate increases to the right,
and the y coordinate increases upward. In the bottom right, positions that are within the target
area are shown as T. After each step (until the target area is reached), the position of the probe
is marked with #. (The bottom-right # is both a position the probe reaches and a position in the
target area.)
Another initial velocity that causes the probe to be within the target area after any step is 6,3:
...............#..#............
...........#........#..........
...............................
......#..............#.........
...............................
...............................
S....................#.........
...............................
...............................
...............................
.....................#.........
....................TTTTTTTTTTT
....................TTTTTTTTTTT
....................TTTTTTTTTTT
....................TTTTTTTTTTT
....................T#TTTTTTTTT
....................TTTTTTTTTTT
Another one is 9,0:
S........#.....................
.................#.............
...............................
........................#......
...............................
....................TTTTTTTTTTT
....................TTTTTTTTTT#
....................TTTTTTTTTTT
....................TTTTTTTTTTT
....................TTTTTTTTTTT
....................TTTTTTTTTTT
One initial velocity that [1m[97mdoesn't[0m cause the probe to be within the target area after any step is
17,-4:
S..............................................................
...............................................................
...............................................................
...............................................................
.................#.............................................
....................TTTTTTTTTTT................................
....................TTTTTTTTTTT................................
....................TTTTTTTTTTT................................
....................TTTTTTTTTTT................................
....................TTTTTTTTTTT..#.............................
....................TTTTTTTTTTT................................
...............................................................
...............................................................
...............................................................
...............................................................
................................................#..............
...............................................................
...............................................................
...............................................................
...............................................................
...............................................................
...............................................................
..............................................................#
The probe appears to pass through the target area, but is never within it after any step. Instead,
it continues down and to the right - only the first few steps are shown.
If you're going to fire a highly scientific probe out of a super cool probe launcher, you might as
well do it with [1m[97mstyle[0m. How high can you make the probe go while still reaching the target area?
In the above example, using an initial velocity of 6,9 is the best you can do, causing the probe to
reach a maximum y position of [1m[97m45[0m. (Any higher initial y velocity causes the probe to overshoot the
target area entirely.)
Find the initial velocity that causes the probe to reach the highest y position and still eventually
be within the target area after any step. [1m[97mWhat is the highest y position it reaches on this
trajectory?[0m
|