Skip to content

Commit d6a3072

Browse files
author
Björn Walter
committed
Start Day 13
1 parent 1115277 commit d6a3072

File tree

8 files changed

+2446
-8
lines changed

8 files changed

+2446
-8
lines changed

11.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def expand_universe(uni):
2020

2121
return uni
2222

23-
def min_dist(uni, source, )
23+
def min_dist(uni, source, destination):
24+
return
2425

2526
def main():
2627
with open("inputs/11_test.txt", "r") as file:

12.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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()

13.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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()

7.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ def compare_hands(self, hand):
5353
else:
5454
return False
5555

56-
57-
58-
5956
def main():
6057
with open("inputs/7_test.txt", "r") as file:
6158
lines = file.readlines()
@@ -65,10 +62,18 @@ def main():
6562
hands.append(Hand(game))
6663
ranking = []
6764
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)
7277

7378

7479
if __name__ == "__main__":

0 commit comments

Comments
 (0)