|
| 1 | +# Day 22: Sand Slabs |
| 2 | +Enough sand has fallen; it can finally filter water for Snow Island. |
| 3 | + |
| 4 | +Well, **almost**. |
| 5 | + |
| 6 | +The sand has been falling as large compacted **bricks** of sand, piling up to form an impressive stack here near the |
| 7 | +edge of Island Island. In order to make use of the sand to filter water, some of the bricks will need to be broken |
| 8 | +apart - nay, **disintegrated** - back into freely flowing sand. |
| 9 | + |
| 10 | +The stack is tall enough that you'll have to be careful about choosing which bricks to disintegrate; if you disintegrate |
| 11 | +the wrong brick, large portions of the stack could topple, which sounds pretty dangerous. |
| 12 | + |
| 13 | +The Elves responsible for water filtering operations took a **snapshot of the bricks while they were still falling** |
| 14 | +(your puzzle input) which should let you work out which bricks are safe to disintegrate. For example: |
| 15 | +``` |
| 16 | +1,0,1~1,2,1 |
| 17 | +0,0,2~2,0,2 |
| 18 | +0,2,3~2,2,3 |
| 19 | +0,0,4~0,2,4 |
| 20 | +2,0,5~2,2,5 |
| 21 | +0,1,6~2,1,6 |
| 22 | +1,1,8~1,1,9 |
| 23 | +``` |
| 24 | +Each line of text in the snapshot represents the position of a single brick at the time the snapshot was taken. The |
| 25 | +position is given as two `x,y,z` coordinates - one for each end of the brick - separated by a tilde (`~`). Each brick |
| 26 | +is made up of a single straight line of cubes, and the Elves were even careful to choose a time for the snapshot that |
| 27 | +had all of the free-falling bricks at **integer positions above the ground**, so the whole snapshot is aligned to a |
| 28 | +three-dimensional cube grid. |
| 29 | + |
| 30 | +A line like `2,2,2~2,2,2` means that both ends of the brick are at the same coordinate - in other words, that the brick |
| 31 | +is a single cube. |
| 32 | + |
| 33 | +Lines like `0,0,10~1,0,10` or `0,0,10~0,1,10` both represent bricks that are **two cubes** in volume, both oriented |
| 34 | +horizontally. The first brick extends in the `x` direction, while the second brick extends in the `y` direction. |
| 35 | + |
| 36 | +A line like `0,0,1~0,0,10` represents a **ten-cube brick** which is oriented **vertically**. One end of the brick is |
| 37 | +the cube located at `0,0,1`, while the other end of the brick is located directly above it at `0,0,10`. |
| 38 | + |
| 39 | +The ground is at `z=0` and is perfectly flat; the lowest `z` value a brick can have is therefore `1`. So, `5,5,1~5,6,1` |
| 40 | +and `0,2,1~0,2,5` are both resting on the ground, but `3,3,2~3,3,3` was above the ground at the time of the snapshot. |
| 41 | + |
| 42 | +Because the snapshot was taken while the bricks were still falling, some bricks will **still be in the air**; you'll |
| 43 | +need to start by figuring out where they will end up. Bricks are magically stabilized, so they **never rotate**, even |
| 44 | +in weird situations like where a long horizontal brick is only supported on one end. Two bricks cannot occupy the same |
| 45 | +position, so a falling brick will come to rest upon the first other brick it encounters. |
| 46 | + |
| 47 | +Here is the same example again, this time with each brick given a letter so it can be marked in diagrams: |
| 48 | +``` |
| 49 | +1,0,1~1,2,1 <- A |
| 50 | +0,0,2~2,0,2 <- B |
| 51 | +0,2,3~2,2,3 <- C |
| 52 | +0,0,4~0,2,4 <- D |
| 53 | +2,0,5~2,2,5 <- E |
| 54 | +0,1,6~2,1,6 <- F |
| 55 | +1,1,8~1,1,9 <- G |
| 56 | +``` |
| 57 | +At the time of the snapshot, from the side so the `x` axis goes left to right, these bricks are arranged like this: |
| 58 | +``` |
| 59 | +x |
| 60 | +012 |
| 61 | +.G. 9 |
| 62 | +.G. 8 |
| 63 | +... 7 |
| 64 | +FFF 6 |
| 65 | +..E 5 z |
| 66 | +D.. 4 |
| 67 | +CCC 3 |
| 68 | +BBB 2 |
| 69 | +.A. 1 |
| 70 | +--- 0 |
| 71 | +``` |
| 72 | +Rotating the perspective 90 degrees so the `y` axis now goes left to right, the same bricks are arranged like this: |
| 73 | +``` |
| 74 | +y |
| 75 | +012 |
| 76 | +.G. 9 |
| 77 | +.G. 8 |
| 78 | +... 7 |
| 79 | +.F. 6 |
| 80 | +EEE 5 z |
| 81 | +DDD 4 |
| 82 | +..C 3 |
| 83 | +B.. 2 |
| 84 | +AAA 1 |
| 85 | +--- 0 |
| 86 | +``` |
| 87 | +Once all of the bricks fall downward as far as they can go, the stack looks like this, where `?` means bricks are |
| 88 | +hidden behind other bricks at that location: |
| 89 | +``` |
| 90 | +x |
| 91 | +012 |
| 92 | +.G. 6 |
| 93 | +.G. 5 |
| 94 | +FFF 4 |
| 95 | +D.E 3 z |
| 96 | +??? 2 |
| 97 | +.A. 1 |
| 98 | +--- 0 |
| 99 | +``` |
| 100 | +Again from the side: |
| 101 | +``` |
| 102 | +y |
| 103 | +012 |
| 104 | +.G. 6 |
| 105 | +.G. 5 |
| 106 | +.F. 4 |
| 107 | +??? 3 z |
| 108 | +B.C 2 |
| 109 | +AAA 1 |
| 110 | +--- 0 |
| 111 | +``` |
| 112 | +Now that all of the bricks have settled, it becomes easier to tell which bricks are supporting which other bricks: |
| 113 | +* Brick `A` is the only brick supporting bricks `B` and `C`. |
| 114 | +* Brick `B` is one of two bricks supporting brick `D` and brick `E`. |
| 115 | +* Brick `C` is the other brick supporting brick `D` and brick `E`. |
| 116 | +* Brick `D` supports brick `F`. |
| 117 | +* Brick `E` also supports brick `F`. |
| 118 | +* Brick `F` supports brick `G`. |
| 119 | +* Brick `G` isn't supporting any bricks. |
| 120 | + |
| 121 | +Your first task is to figure out **which bricks are safe to disintegrate**. A brick can be safely disintegrated if, |
| 122 | +after removing it, **no other bricks** would fall further directly downward. Don't actually disintegrate any bricks - |
| 123 | +just determine what would happen if, for each brick, only that brick were disintegrated. Bricks can be disintegrated |
| 124 | +even if they're completely surrounded by other bricks; you can squeeze between bricks if you need to. |
| 125 | + |
| 126 | +In this example, the bricks can be disintegrated as follows: |
| 127 | +* Brick `A` cannot be disintegrated safely; if it were disintegrated, bricks `B` and `C` would both fall. |
| 128 | +* Brick `B` **can** be disintegrated; the bricks above it (`D` and `E`) would still be supported by brick `C`. |
| 129 | +* Brick `C` **can** be disintegrated; the bricks above it (`D` and `E`) would still be supported by brick `B`. |
| 130 | +* Brick `D` **can** be disintegrated; the brick above it (`F`) would still be supported by brick `E`. |
| 131 | +* Brick `E` **can** be disintegrated; the brick above it (`F`) would still be supported by brick `D`. |
| 132 | +* Brick `F` cannot be disintegrated; the brick above it (`G`) would fall. |
| 133 | +* Brick `G` **can** be disintegrated; it does not support any other bricks. |
| 134 | + |
| 135 | +So, in this example, **`5`** bricks can be safely disintegrated. |
| 136 | + |
| 137 | +Figure how the blocks will settle based on the snapshot. Once they've settled, consider disintegrating a single brick; |
| 138 | +**how many bricks could be safely chosen as the one to get disintegrated**? |
0 commit comments