diff --git a/src/Year_2021/P12.py b/src/Year_2021/P12.py index 5d4b39f..9d91e85 100644 --- a/src/Year_2021/P12.py +++ b/src/Year_2021/P12.py @@ -156,5 +156,66 @@ def part_1() -> None: print(f"There are {ans} paths visiting small caves") +# --- Part Two --- + +# After reviewing the available paths, you realize you might have time to visit +# a single small cave twice. Specifically, big caves can be visited any number +# of times, a single small cave can be visited at most twice, and the remaining +# small caves can be visited at most once. However, the caves named start and +# end can only be visited exactly once each: once you leave the start cave, you +# may not return to it, and once you reach the end cave, the path must end +# immediately. + +# Now, the 36 possible paths through the first example above are: + +# start,A,b,A,b,A,c,A,end +# start,A,b,A,b,A,end +# start,A,b,A,b,end +# start,A,b,A,c,A,b,A,end +# start,A,b,A,c,A,b,end +# start,A,b,A,c,A,c,A,end +# start,A,b,A,c,A,end +# start,A,b,A,end +# start,A,b,d,b,A,c,A,end +# start,A,b,d,b,A,end +# start,A,b,d,b,end +# start,A,b,end +# start,A,c,A,b,A,b,A,end +# start,A,c,A,b,A,b,end +# start,A,c,A,b,A,c,A,end +# start,A,c,A,b,A,end +# start,A,c,A,b,d,b,A,end +# start,A,c,A,b,d,b,end +# start,A,c,A,b,end +# start,A,c,A,c,A,b,A,end +# start,A,c,A,c,A,b,end +# start,A,c,A,c,A,end +# start,A,c,A,end +# start,A,end +# start,b,A,b,A,c,A,end +# start,b,A,b,A,end +# start,b,A,b,end +# start,b,A,c,A,b,A,end +# start,b,A,c,A,b,end +# start,b,A,c,A,c,A,end +# start,b,A,c,A,end +# start,b,A,end +# start,b,d,b,A,c,A,end +# start,b,d,b,A,end +# start,b,d,b,end +# start,b,end + +# The slightly larger example above now has 103 paths through it, and the even +# larger example now has 3509 paths through it. + +# Given these new rules, how many paths through this cave system are there? + + +def part_2() -> None: + ans = dfs("start", caves_map, {"start"}, already_visited=True) + print(f"There are {ans} paths in total") + + if __name__ == "__main__": part_1() + part_2()