Commit 66cd61a 1 parent 6e4fef3 commit 66cd61a Copy full SHA for 66cd61a
File tree 1 file changed +33
-0
lines changed
1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ import re
2
+ from tqdm import tqdm
3
+
4
+
5
+ BASE_REGEX : str = "$$n$$: ([\\ s\\ d]*)"
6
+
7
+ with open ("input" , "r" ) as input_file :
8
+ input_text : str = input_file .read ().strip ()
9
+
10
+
11
+ def get_values (line_name : str ) -> list [int ]:
12
+ global input_text
13
+ regex : str = BASE_REGEX .replace ("$$n$$" , line_name .capitalize ())
14
+ search : re .Match = re .search (regex , input_text )
15
+ result : str = search .groups ()[0 ].split ()
16
+ return [int (n ) for n in result ]
17
+
18
+
19
+ def calculate_distance (windup : int , total : int ):
20
+ # speed[mm/ms] = windup[ms]
21
+ runtime : int = total - windup # [ms]
22
+ return runtime * windup # [mm]
23
+
24
+
25
+ time : int = int ("" .join ([str (t ) for t in get_values ("time" )]))
26
+ dist : int = int ("" .join ([str (d ) for d in get_values ("distance" )]))
27
+
28
+ winning_windups : int = 0
29
+ for windup in tqdm (range (time )):
30
+ reached_dist : int = calculate_distance (windup , time )
31
+ if reached_dist > dist :
32
+ winning_windups += 1
33
+ print (f"SOLVE: { winning_windups } " )
You can’t perform that action at this time.
0 commit comments