description.txt 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. --- Day 12: Passage Pathing ---
  2. With your submarine's subterranean subsystems subsisting suboptimally, the only way you're getting out of this cave anytime soon is by finding a path yourself. Not just a path - the only way to know if you've found the best path is to find all of them.
  3. Fortunately, the sensors are still mostly working, and so you build a rough map of the remaining caves (your puzzle input). For example:
  4. start-A
  5. start-b
  6. A-c
  7. A-b
  8. b-d
  9. A-end
  10. b-end
  11. This is a list of how all of the caves are connected. You start in the cave named start, and your destination is the cave named end. An entry like b-d means that cave b is connected to cave d - that is, you can move between them.
  12. So, the above cave system looks roughly like this:
  13. start
  14. / \
  15. c--A-----b--d
  16. \ /
  17. end
  18. Your goal is to find the number of distinct paths that start at start, end at end, and don't visit small caves more than once. There are two types of caves: big caves (written in uppercase, like A) and small caves (written in lowercase, like b). It would be a waste of time to visit any small cave more than once, but big caves are large enough that it might be worth visiting them multiple times. So, all paths you find should visit small caves at most once, and can visit big caves any number of times.
  19. Given these rules, there are 10 paths through this example cave system:
  20. start,A,b,A,c,A,end
  21. start,A,b,A,end
  22. start,A,b,end
  23. start,A,c,A,b,A,end
  24. start,A,c,A,b,end
  25. start,A,c,A,end
  26. start,A,end
  27. start,b,A,c,A,end
  28. start,b,A,end
  29. start,b,end
  30. (Each line in the above list corresponds to a single path; the caves visited by that path are listed in the order they are visited and separated by commas.)
  31. Note that in this cave system, cave d is never visited by any path: to do so, cave b would need to be visited twice (once on the way to cave d and a second time when returning from cave d), and since cave b is small, this is not allowed.
  32. Here is a slightly larger example:
  33. dc-end
  34. HN-start
  35. start-kj
  36. dc-start
  37. dc-HN
  38. LN-dc
  39. HN-end
  40. kj-sa
  41. kj-HN
  42. kj-dc
  43. The 19 paths through it are as follows:
  44. start,HN,dc,HN,end
  45. start,HN,dc,HN,kj,HN,end
  46. start,HN,dc,end
  47. start,HN,dc,kj,HN,end
  48. start,HN,end
  49. start,HN,kj,HN,dc,HN,end
  50. start,HN,kj,HN,dc,end
  51. start,HN,kj,HN,end
  52. start,HN,kj,dc,HN,end
  53. start,HN,kj,dc,end
  54. start,dc,HN,end
  55. start,dc,HN,kj,HN,end
  56. start,dc,end
  57. start,dc,kj,HN,end
  58. start,kj,HN,dc,HN,end
  59. start,kj,HN,dc,end
  60. start,kj,HN,end
  61. start,kj,dc,HN,end
  62. start,kj,dc,end
  63. Finally, this even larger example has 226 paths through it:
  64. fs-end
  65. he-DX
  66. fs-he
  67. start-DX
  68. pj-DX
  69. end-zg
  70. zg-sl
  71. zg-pj
  72. pj-he
  73. RW-he
  74. fs-DX
  75. pj-RW
  76. zg-RW
  77. start-pj
  78. he-WI
  79. zg-he
  80. pj-fs
  81. start-RW
  82. How many paths through this cave system are there that visit small caves at most once?
  83. Your puzzle answer was 3463.
  84. --- Part Two ---
  85. 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.
  86. Now, the 36 possible paths through the first example above are:
  87. start,A,b,A,b,A,c,A,end
  88. start,A,b,A,b,A,end
  89. start,A,b,A,b,end
  90. start,A,b,A,c,A,b,A,end
  91. start,A,b,A,c,A,b,end
  92. start,A,b,A,c,A,c,A,end
  93. start,A,b,A,c,A,end
  94. start,A,b,A,end
  95. start,A,b,d,b,A,c,A,end
  96. start,A,b,d,b,A,end
  97. start,A,b,d,b,end
  98. start,A,b,end
  99. start,A,c,A,b,A,b,A,end
  100. start,A,c,A,b,A,b,end
  101. start,A,c,A,b,A,c,A,end
  102. start,A,c,A,b,A,end
  103. start,A,c,A,b,d,b,A,end
  104. start,A,c,A,b,d,b,end
  105. start,A,c,A,b,end
  106. start,A,c,A,c,A,b,A,end
  107. start,A,c,A,c,A,b,end
  108. start,A,c,A,c,A,end
  109. start,A,c,A,end
  110. start,A,end
  111. start,b,A,b,A,c,A,end
  112. start,b,A,b,A,end
  113. start,b,A,b,end
  114. start,b,A,c,A,b,A,end
  115. start,b,A,c,A,b,end
  116. start,b,A,c,A,c,A,end
  117. start,b,A,c,A,end
  118. start,b,A,end
  119. start,b,d,b,A,c,A,end
  120. start,b,d,b,A,end
  121. start,b,d,b,end
  122. start,b,end
  123. The slightly larger example above now has 103 paths through it, and the even larger example now has 3509 paths through it.
  124. Given these new rules, how many paths through this cave system are there?
  125. Your puzzle answer was 91533.