Skip to content

Commit 8f2634f

Browse files
committed
Finished day 13
1 parent 42d72f1 commit 8f2634f

File tree

4 files changed

+937
-17
lines changed

4 files changed

+937
-17
lines changed

Day12puzzle1.py

+48-17
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,70 @@ def __init__(self, letter, data):
1717
self.big=True
1818

1919
cavedict = {}
20+
2021
caveidlist = []
2122
for row in data:
2223
for col in row:
2324
if col not in caveidlist:
2425
caveidlist.append(col)
2526
cavedict[col] = cave(col, data)
26-
smallcavelist = []
27-
for row in caveidlist:
28-
if not cavedict[row].big:
29-
smallcavelist[row] = row
30-
3127

3228

3329
class paths:
3430
def __init__(self, cavedict):
3531
self.cavelist = cavedict
36-
self.optionslist = []
32+
self.optionslist = [[len(cavedict["start"].connections)-1, "start"]]
3733
self.path = [cavedict["start"]]
34+
self.count=0
3835

3936
def genpath(self):
40-
self.optionslist.append(len(cavedict["start"].connections)-1)
41-
restricted = []
42-
while True:
43-
if(cavedict[self.path[-1].connections[self.optionslist[-1]]] not in (restricted)):
44-
self.path.append(cavedict[self.path[-1].connections[self.optionslist[-1]]])
45-
if not self.path[-1].big:
46-
restricted.append(self.path[-1])
47-
if(self.path[-1].id == "end"):
48-
return self.path
49-
self.optionslist.append
37+
self.restricted = [cavedict["start"]]
38+
self.path = [cavedict["start"]]
39+
if(self.optionslist[0][0]>-1):
40+
while(self.poplast()):
41+
x=1
42+
x=0
43+
while(self.addcave(x)):
44+
print(len(self.optionslist))
45+
print(x)
46+
print(self.path[-1].id)
47+
x+=1
48+
if(self.path[-1].id=="end"):
49+
self.count+=1
50+
break
51+
52+
return True
53+
return False
54+
55+
56+
57+
58+
59+
def addcave(self, x):
60+
if(cavedict[self.path[-1].connections[self.optionslist[x][0]]] not in (self.restricted)):
61+
self.path.append(cavedict[self.path[-1].connections[self.optionslist[x][0]]])
62+
if not self.path[-1].big:
63+
self.restricted.append(self.path[-1])
64+
if(self.path[-1].id!="end" and len(self.optionslist)<len(self.path)):
65+
self.optionslist.append([len(self.path[-1].connections)-1, self.path[-1].id])
66+
else:
67+
self.optionslist[-1][0]-=1
68+
return True
69+
self.optionslist[-1][0]-=1
70+
return False
5071

51-
72+
def poplast(self):
73+
if(self.optionslist[-1][0]<0):
74+
self.optionslist.pop()
75+
self.optionslist[-1][0]-=1
76+
if(self.optionslist[-1][0]<0):
77+
return True
78+
return False
5279

80+
pathgen = paths(cavedict)
81+
while(pathgen.genpath()):
82+
x=1
83+
print(pathgen.count)
5384

5485

5586

0 commit comments

Comments
 (0)