File tree 1 file changed +47
-2
lines changed
1 file changed +47
-2
lines changed Original file line number Diff line number Diff line change
1
+ from tqdm import trange
1
2
3
+ def load_data (file_path : str ) -> list :
4
+ with open (file_path , 'r' ) as file :
5
+ data = file .readlines ()
2
6
7
+ springs = []
8
+ instructions = []
9
+ for dat in data :
10
+ dat = dat .strip ()
11
+ spring , instr = dat .split (" " )
12
+ springs .append (spring )
13
+ instructions .append (instr )
3
14
4
- def calculate_arrangements (input_line : str ):
5
- groups = input_line .split ('.' )
15
+ return springs , instructions
16
+
17
+ def calculate_arrangements (string : str , arrangement_idx : int , N_quest : int ) -> str :
18
+
19
+ arrangement_idx = bin (arrangement_idx )[2 :].zfill (N_quest )
20
+ qidx = 0
21
+ result = ""
22
+ for char in string :
23
+ if char == "?" :
24
+ if arrangement_idx [qidx ] == "1" :
25
+ result += "#"
26
+ else :
27
+ result += "."
28
+ qidx += 1
29
+ else :
30
+ result += char
31
+
32
+ return result
33
+
34
+ if __name__ == "__main__" :
35
+ springs , instructions = load_data ("input.txt" )
36
+
37
+ spring = springs [0 ]
38
+ instr = instructions [0 ]
39
+
40
+ count_q = spring .count ("?" )
41
+ results = []
42
+ for arr_idx in trange (0 , 2 ** instr .count ("?" )):
43
+ results .append (calculate_arrangements (spring , arr_idx , count_q ))
44
+ print (len (results ))
45
+
46
+ # Note for next time: Sorry
47
+ # We have a function to replace ? with stuff
48
+ # This slow method gives us every possible case
49
+ # Filter by obeying instructions
50
+ # Get money
You can’t perform that action at this time.
0 commit comments