File tree 1 file changed +10
-9
lines changed
1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change 1
1
from sympy import *
2
2
import math
3
3
4
+ def intersects (t ,d ):
5
+ h = symbols ('h' )
6
+ intersects = solve (int (t )* h - h ** 2 - int (d )- 1 , h )
7
+ win_count = floor (intersects [1 ])- math .ceil (intersects [0 ])+ 1
8
+ return win_count
9
+
4
10
def main ():
5
11
with open ("inputs/6.txt" , "r" ) as file :
6
12
lines = file .readlines ()
@@ -12,21 +18,16 @@ def main():
12
18
h = symbols ('h' )
13
19
for t , d in zip (times , distances ):
14
20
# Solve t*h-h**2-d-1 = 0
15
- intersects = solve (int (t )* h - h ** 2 - int (d )- 1 , h )
16
- win_count = floor (intersects [1 ])- math .ceil (intersects [0 ])+ 1
17
- wins *= floor (intersects [1 ])- math .ceil (intersects [0 ])+ 1
21
+ win_count = intersects (t ,d )
22
+ wins *= win_count
18
23
print (f"Answer 1: { wins } " )
19
24
20
25
# Part 2
21
- wins = 1
22
26
# Clump times and distances together.
23
27
t = '' .join (times )
24
28
d = '' .join (distances )
25
- intersects = solve (int (t )* h - h ** 2 - int (d )- 1 , h )
26
- win_count = floor (intersects [1 ])- math .ceil (intersects [0 ])+ 1
27
- print (win_count )
28
- wins *= floor (intersects [1 ])- math .ceil (intersects [0 ])+ 1.
29
- print (f"Answer 2: { wins } " )
29
+ win_count = intersects (t ,d )
30
+ print (f"Answer 2: { win_count } " )
30
31
31
32
if __name__ == "__main__" :
32
33
main ()
You can’t perform that action at this time.
0 commit comments