Skip to content

Commit 378470f

Browse files
authored
Add files via upload
1 parent a2fa2fb commit 378470f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Day 17.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
test = [20,30,-10,-5]
2+
inp = open('Day 17.txt','r').read()
3+
inp = [int(i) for i in [inp.split('=')[1].split('.')[0],inp.split(',')[0].split('.')[-1],inp.split('=')[2].split('.')[0],inp.split('.')[-1]]]
4+
5+
def part1(inp):
6+
min_y = inp[2]
7+
print(min_y*(min_y+1)//2)
8+
9+
from math import sqrt
10+
def part2(inp):
11+
min_x,max_x,min_y,max_y = inp
12+
total_vel = 0
13+
for vel_y in range(min_y,abs(min_y)):
14+
for vel_x in range(int(sqrt(min_x)),max_x+1):
15+
x = 0
16+
y = 0
17+
curr_x = vel_x
18+
curr_y = vel_y
19+
while y > max_y or x < min_x:
20+
x += curr_x
21+
if curr_x > 0: curr_x -= 1
22+
if curr_x == 0 and not y > max_y: break
23+
y += curr_y
24+
curr_y -= 1
25+
if x >= min_x and x <= max_x and y >= min_y and y <= max_y:
26+
total_vel += 1
27+
print(total_vel)
28+
29+
part1(inp)
30+
part2(inp)

0 commit comments

Comments
 (0)