-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay17.py
More file actions
36 lines (35 loc) · 1.1 KB
/
Day17.py
File metadata and controls
36 lines (35 loc) · 1.1 KB
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
import re
def Trickshot():
f = open("input day 17.txt", "r")
lines = f.readlines()
numbers = re.sub(r'[^-\d]', " ", lines[0]).split(' ')
print(numbers)
Coords = []
for item in numbers:
if item != '':
Coords.append(int(item))
print(Coords)
yMax = 0
maxV = (0, 0)
hits = []
for xV in range(0, Coords[1] + 1):
for yV in range(Coords[2], 300):
yTajectory = []
xSpeed = xV
ySpeed = yV
xPos = 0
yPos = 0
while xPos <= Coords[1] and yPos >= Coords[2]:
xPos += xSpeed
yPos += ySpeed
yTajectory.append(yPos)
if xPos >= Coords[0] and xPos <= Coords[1] and yPos >= Coords[2] and yPos <= Coords[3]:
hits.append(str((xV,yV )))
if max(yTajectory) > yMax:
yMax = max(yTajectory)
maxV = (xV, yV)
break
if xSpeed != 0:
xSpeed -= 1
ySpeed -= 1
print(maxV, yMax, len(hits))