description.txt 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. --- Day 14: Regolith Reservoir ---
  2. The distress signal leads you to a giant waterfall! Actually, hang on - the signal seems like it's coming from the waterfall itself, and that doesn't make any sense. However, you do notice a little path that leads behind the waterfall.
  3. Correction: the distress signal leads you behind a giant waterfall! There seems to be a large cave system here, and the signal definitely leads further inside.
  4. As you begin to make your way deeper underground, you feel the ground rumble for a moment. Sand begins pouring into the cave! If you don't quickly figure out where the sand is going, you could quickly become trapped!
  5. Fortunately, your familiarity with analyzing the path of falling material will come in handy here. You scan a two-dimensional vertical slice of the cave above you (your puzzle input) and discover that it is mostly air with structures made of rock.
  6. Your scan traces the path of each solid rock structure and reports the x,y coordinates that form the shape of the path, where x represents distance to the right and y represents distance down. Each path appears as a single line of text in your scan. After the first point of each path, each point indicates the end of a straight horizontal or vertical line to be drawn from the previous point. For example:
  7. 498,4 -> 498,6 -> 496,6
  8. 503,4 -> 502,4 -> 502,9 -> 494,9
  9. This scan means that there are two paths of rock; the first path consists of two straight lines, and the second path consists of three straight lines. (Specifically, the first path consists of a line of rock from 498,4 through 498,6 and another line of rock from 498,6 through 496,6.)
  10. The sand is pouring into the cave from point 500,0.
  11. Drawing rock as #, air as ., and the source of the sand as +, this becomes:
  12. 4 5 5
  13. 9 0 0
  14. 4 0 3
  15. 0 ......+...
  16. 1 ..........
  17. 2 ..........
  18. 3 ..........
  19. 4 ....#...##
  20. 5 ....#...#.
  21. 6 ..###...#.
  22. 7 ........#.
  23. 8 ........#.
  24. 9 #########.
  25. Sand is produced one unit at a time, and the next unit of sand is not produced until the previous unit of sand comes to rest. A unit of sand is large enough to fill one tile of air in your scan.
  26. A unit of sand always falls down one step if possible. If the tile immediately below is blocked (by rock or sand), the unit of sand attempts to instead move diagonally one step down and to the left. If that tile is blocked, the unit of sand attempts to instead move diagonally one step down and to the right. Sand keeps moving as long as it is able to do so, at each step trying to move down, then down-left, then down-right. If all three possible destinations are blocked, the unit of sand comes to rest and no longer moves, at which point the next unit of sand is created back at the source.
  27. So, drawing sand that has come to rest as o, the first unit of sand simply falls straight down and then stops:
  28. ......+...
  29. ..........
  30. ..........
  31. ..........
  32. ....#...##
  33. ....#...#.
  34. ..###...#.
  35. ........#.
  36. ......o.#.
  37. #########.
  38. The second unit of sand then falls straight down, lands on the first one, and then comes to rest to its left:
  39. ......+...
  40. ..........
  41. ..........
  42. ..........
  43. ....#...##
  44. ....#...#.
  45. ..###...#.
  46. ........#.
  47. .....oo.#.
  48. #########.
  49. After a total of five units of sand have come to rest, they form this pattern:
  50. ......+...
  51. ..........
  52. ..........
  53. ..........
  54. ....#...##
  55. ....#...#.
  56. ..###...#.
  57. ......o.#.
  58. ....oooo#.
  59. #########.
  60. After a total of 22 units of sand:
  61. ......+...
  62. ..........
  63. ......o...
  64. .....ooo..
  65. ....#ooo##
  66. ....#ooo#.
  67. ..###ooo#.
  68. ....oooo#.
  69. ...ooooo#.
  70. #########.
  71. Finally, only two more units of sand can possibly come to rest:
  72. ......+...
  73. ..........
  74. ......o...
  75. .....ooo..
  76. ....#ooo##
  77. ...o#ooo#.
  78. ..###ooo#.
  79. ....oooo#.
  80. .o.ooooo#.
  81. #########.
  82. Once all 24 units of sand shown above have come to rest, all further sand flows out the bottom, falling into the endless void. Just for fun, the path any new sand takes before falling forever is shown here with ~:
  83. .......+...
  84. .......~...
  85. ......~o...
  86. .....~ooo..
  87. ....~#ooo##
  88. ...~o#ooo#.
  89. ..~###ooo#.
  90. ..~..oooo#.
  91. .~o.ooooo#.
  92. ~#########.
  93. ~..........
  94. ~..........
  95. ~..........
  96. Using your scan, simulate the falling sand. How many units of sand come to rest before sand starts flowing into the abyss below?
  97. Your puzzle answer was 793.
  98. --- Part Two ---
  99. You realize you misread the scan. There isn't an endless void at the bottom of the scan - there's floor, and you're standing on it!
  100. You don't have time to scan the floor, so assume the floor is an infinite horizontal line with a y coordinate equal to two plus the highest y coordinate of any point in your scan.
  101. In the example above, the highest y coordinate of any point is 9, and so the floor is at y=11. (This is as if your scan contained one extra rock path like -infinity,11 -> infinity,11.) With the added floor, the example above now looks like this:
  102. ...........+........
  103. ....................
  104. ....................
  105. ....................
  106. .........#...##.....
  107. .........#...#......
  108. .......###...#......
  109. .............#......
  110. .............#......
  111. .....#########......
  112. ....................
  113. <-- etc #################### etc -->
  114. To find somewhere safe to stand, you'll need to simulate falling sand until a unit of sand comes to rest at 500,0, blocking the source entirely and stopping the flow of sand into the cave. In the example above, the situation finally looks like this after 93 units of sand come to rest:
  115. ............o............
  116. ...........ooo...........
  117. ..........ooooo..........
  118. .........ooooooo.........
  119. ........oo#ooo##o........
  120. .......ooo#ooo#ooo.......
  121. ......oo###ooo#oooo......
  122. .....oooo.oooo#ooooo.....
  123. ....oooooooooo#oooooo....
  124. ...ooo#########ooooooo...
  125. ..ooooo.......ooooooooo..
  126. #########################
  127. Using your scan, simulate the falling sand until the source of the sand becomes blocked. How many units of sand come to rest?
  128. Your puzzle answer was 24166.