File tree 8 files changed +2446
-8
lines changed
8 files changed +2446
-8
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,8 @@ def expand_universe(uni):
20
20
21
21
return uni
22
22
23
- def min_dist (uni , source , )
23
+ def min_dist (uni , source , destination ):
24
+ return
24
25
25
26
def main ():
26
27
with open ("inputs/11_test.txt" , "r" ) as file :
Original file line number Diff line number Diff line change
1
+ import numpy as np
2
+
3
+ class Record ():
4
+ def __init__ (self , line ):
5
+ self .condition = line [0 ]
6
+ self .criteria = [int (item ) for item in line [1 ].split ("," )]
7
+ #print(self.criteria)
8
+
9
+ def get_combinations (cond ):
10
+ idx = cond .find ("?" )
11
+
12
+ if idx == - 1 :
13
+ combination = []
14
+ count = 0
15
+ for idx , i in enumerate (cond ):
16
+ if i == "#" :
17
+ count += 1
18
+ if i == "." :
19
+ if count != 0 :
20
+ combination .append (count )
21
+ count = 0
22
+ if idx == len (cond )- 1 and count != 0 :
23
+ combination .append (count )
24
+
25
+ return [combination ]
26
+
27
+ option1 = cond [:idx ] + "#" + cond [idx + 1 :]
28
+ option2 = cond [:idx ] + "." + cond [idx + 1 :]
29
+
30
+ combinations1 = get_combinations (option1 )
31
+ combinations2 = get_combinations (option2 )
32
+
33
+ return combinations1 + combinations2
34
+
35
+ def find_arr (rec ):
36
+ combs = get_combinations (rec .condition )
37
+ arr = 0
38
+ for comb in combs :
39
+ if comb == rec .criteria :
40
+ arr += 1
41
+ return arr
42
+
43
+ def main ():
44
+ with open ("inputs/12.txt" , "r" ) as file :
45
+ lines = file .readlines ()
46
+
47
+ records = [Record (line .strip ("\n " ).split ()) for line in lines ]
48
+ arrs = []
49
+ for record in records :
50
+ arrs .append (find_arr (record ))
51
+ print (arrs )
52
+ print (sum (arrs ))
53
+
54
+ #universe = np.array([[e for e in line.strip("\n")] for line in lines])
55
+
56
+ if __name__ == "__main__" :
57
+ main ()
Original file line number Diff line number Diff line change
1
+ import numpy as np
2
+
3
+
4
+ def find_symmetry (pattern ):
5
+ #horizontal
6
+ for i , row in enumerate (pattern ):
7
+ top = pattern [:i ]
8
+ bottom = np .flip (pattern [i :i * 2 ], axis = 0 )
9
+ if np .array_equal (top , bottom ) and i != 0 :
10
+ return i , "horizontal"
11
+ for j , _ in enumerate (pattern [0 ]):
12
+ left = pattern [:,:j ]
13
+ right = np .flip (pattern [:, j :j * 2 ], axis = 0 )
14
+ print (left , right )
15
+ if np .array_equal (left , right ) and j != 0 :
16
+ return j , "vertical"
17
+
18
+
19
+ def main ():
20
+ with open ("inputs/13_test.txt" , "r" ) as file :
21
+ lines = file .readlines ()
22
+ patterns = []
23
+ pattern = []
24
+ for i , line in enumerate (lines ):
25
+ if line == "\n " or i == len (lines )- 1 :
26
+ patterns .append (np .array ([list (map (str , row )) for row in pattern ]))
27
+ pattern = []
28
+ else :
29
+ pattern .append (line .strip ("\n " ))
30
+ find_symmetry (patterns [0 ])
31
+
32
+
33
+ #print(patterns)
34
+ if __name__ == "__main__" :
35
+ main ()
Original file line number Diff line number Diff line change @@ -53,9 +53,6 @@ def compare_hands(self, hand):
53
53
else :
54
54
return False
55
55
56
-
57
-
58
-
59
56
def main ():
60
57
with open ("inputs/7_test.txt" , "r" ) as file :
61
58
lines = file .readlines ()
@@ -65,10 +62,18 @@ def main():
65
62
hands .append (Hand (game ))
66
63
ranking = []
67
64
for hand in hands :
68
- for idx , rank in enumerate (ranking ):
69
- if hand .compare_hands (rank ) == - 1 :
70
- ranking .insert (idx , hand )
71
- break
65
+ if len (ranking ) == 0 :
66
+ ranking .append (hand )
67
+ else :
68
+ for idx , rank in enumerate (ranking ):
69
+ if hand .compare_hands (rank ) == False :
70
+ ranking = ranking [:idx ] + [hand ] + ranking [idx :]
71
+ #ranking.insert(idx, hand)
72
+ break
73
+ if idx == len (ranking )- 1 :
74
+ ranking .append (hand )
75
+ for rank in ranking :
76
+ print (rank .cards )
72
77
73
78
74
79
if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments