|
@@ -21,18 +21,9 @@ def find_paths_1(current, prev):
|
|
|
|
|
|
print(find_paths_1("start", ["start"]))
|
|
|
|
|
|
-def ndup(ls):
|
|
|
- curr = []
|
|
|
- dups = 0
|
|
|
- for l in ls:
|
|
|
- if l in curr and l.islower():
|
|
|
- dups += 1
|
|
|
- curr.append(l)
|
|
|
- return dups
|
|
|
-
|
|
|
-def find_paths_2(current, prev):
|
|
|
+def find_paths_2(current, prev, duped=False):
|
|
|
if current == "end":
|
|
|
return 1
|
|
|
- return sum([find_paths_2(next, prev + [current]) for next in neighbour_map[current] if not ((next.islower() and next in prev and ndup(prev + [current]) > 0) or next == "start")])
|
|
|
+ return sum([find_paths_2(next, prev + [current], duped or (next.islower() and next in prev)) for next in neighbour_map[current] if not ((duped and next.islower() and (next in prev)) or next == "start")])
|
|
|
|
|
|
print(find_paths_2("start", []))
|