@@ -17,39 +17,70 @@ def __init__(self, letter, data):
17
17
self .big = True
18
18
19
19
cavedict = {}
20
+
20
21
caveidlist = []
21
22
for row in data :
22
23
for col in row :
23
24
if col not in caveidlist :
24
25
caveidlist .append (col )
25
26
cavedict [col ] = cave (col , data )
26
- smallcavelist = []
27
- for row in caveidlist :
28
- if not cavedict [row ].big :
29
- smallcavelist [row ] = row
30
-
31
27
32
28
33
29
class paths :
34
30
def __init__ (self , cavedict ):
35
31
self .cavelist = cavedict
36
- self .optionslist = []
32
+ self .optionslist = [[ len ( cavedict [ "start" ]. connections ) - 1 , "start" ] ]
37
33
self .path = [cavedict ["start" ]]
34
+ self .count = 0
38
35
39
36
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
50
71
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
52
79
80
+ pathgen = paths (cavedict )
81
+ while (pathgen .genpath ()):
82
+ x = 1
83
+ print (pathgen .count )
53
84
54
85
55
86
0 commit comments