advent2022

Advent of Code 2022 Solutions
git clone git://bsandro.tech/advent2022
Log | Files | Refs | README | LICENSE

task.txt (6152B)


      1 --- Day 15: Beacon Exclusion Zone ---
      2 
      3 You feel the ground rumble again as the distress signal leads you to a large network of subterranean tunnels. You don't have time to search them all, but you don't need to: your pack contains a set of deployable sensors that you imagine were originally built to locate lost Elves.
      4 
      5 The sensors aren't very powerful, but that's okay; your handheld device indicates that you're close enough to the source of the distress signal to use them. You pull the emergency sensor system out of your pack, hit the big button on top, and the sensors zoom off down the tunnels.
      6 
      7 Once a sensor finds a spot it thinks will give it a good reading, it attaches itself to a hard surface and begins monitoring for the nearest signal source beacon. Sensors and beacons always exist at integer coordinates. Each sensor knows its own position and can determine the position of a beacon precisely; however, sensors can only lock on to the one beacon closest to the sensor as measured by the Manhattan distance. (There is never a tie where two beacons are the same distance to a sensor.)
      8 
      9 It doesn't take long for the sensors to report back their positions and closest beacons (your puzzle input). For example:
     10 
     11 Sensor at x=2, y=18: closest beacon is at x=-2, y=15
     12 Sensor at x=9, y=16: closest beacon is at x=10, y=16
     13 Sensor at x=13, y=2: closest beacon is at x=15, y=3
     14 Sensor at x=12, y=14: closest beacon is at x=10, y=16
     15 Sensor at x=10, y=20: closest beacon is at x=10, y=16
     16 Sensor at x=14, y=17: closest beacon is at x=10, y=16
     17 Sensor at x=8, y=7: closest beacon is at x=2, y=10
     18 Sensor at x=2, y=0: closest beacon is at x=2, y=10
     19 Sensor at x=0, y=11: closest beacon is at x=2, y=10
     20 Sensor at x=20, y=14: closest beacon is at x=25, y=17
     21 Sensor at x=17, y=20: closest beacon is at x=21, y=22
     22 Sensor at x=16, y=7: closest beacon is at x=15, y=3
     23 Sensor at x=14, y=3: closest beacon is at x=15, y=3
     24 Sensor at x=20, y=1: closest beacon is at x=15, y=3
     25 
     26 So, consider the sensor at 2,18; the closest beacon to it is at -2,15. For the sensor at 9,16, the closest beacon to it is at 10,16.
     27 
     28 Drawing sensors as S and beacons as B, the above arrangement of sensors and beacons looks like this:
     29 
     30                1    1    2    2
     31      0    5    0    5    0    5
     32  0 ....S.......................
     33  1 ......................S.....
     34  2 ...............S............
     35  3 ................SB..........
     36  4 ............................
     37  5 ............................
     38  6 ............................
     39  7 ..........S.......S.........
     40  8 ............................
     41  9 ............................
     42 10 ....B.......................
     43 11 ..S.........................
     44 12 ............................
     45 13 ............................
     46 14 ..............S.......S.....
     47 15 B...........................
     48 16 ...........SB...............
     49 17 ................S..........B
     50 18 ....S.......................
     51 19 ............................
     52 20 ............S......S........
     53 21 ............................
     54 22 .......................B....
     55 
     56 This isn't necessarily a comprehensive map of all beacons in the area, though. Because each sensor only identifies its closest beacon, if a sensor detects a beacon, you know there are no other beacons that close or closer to that sensor. There could still be beacons that just happen to not be the closest beacon to any sensor. Consider the sensor at 8,7:
     57 
     58                1    1    2    2
     59      0    5    0    5    0    5
     60 -2 ..........#.................
     61 -1 .........###................
     62  0 ....S...#####...............
     63  1 .......#######........S.....
     64  2 ......#########S............
     65  3 .....###########SB..........
     66  4 ....#############...........
     67  5 ...###############..........
     68  6 ..#################.........
     69  7 .#########S#######S#........
     70  8 ..#################.........
     71  9 ...###############..........
     72 10 ....B############...........
     73 11 ..S..###########............
     74 12 ......#########.............
     75 13 .......#######..............
     76 14 ........#####.S.......S.....
     77 15 B........###................
     78 16 ..........#SB...............
     79 17 ................S..........B
     80 18 ....S.......................
     81 19 ............................
     82 20 ............S......S........
     83 21 ............................
     84 22 .......................B....
     85 
     86 This sensor's closest beacon is at 2,10, and so you know there are no beacons that close or closer (in any positions marked #).
     87 
     88 None of the detected beacons seem to be producing the distress signal, so you'll need to work out where the distress beacon is by working out where it isn't. For now, keep things simple by counting the positions where a beacon cannot possibly be along just a single row.
     89 
     90 So, suppose you have an arrangement of beacons and sensors like in the example above and, just in the row where y=10, you'd like to count the number of positions a beacon cannot possibly exist. The coverage from all sensors near that row looks like this:
     91 
     92                  1    1    2    2
     93        0    5    0    5    0    5
     94  9 ...#########################...
     95 10 ..####B######################..
     96 11 .###S#############.###########.
     97 
     98 In this example, in the row where y=10, there are 26 positions where a beacon cannot be present.
     99 
    100 Consult the report from the sensors you just deployed. In the row where y=2000000, how many positions cannot contain a beacon?
    101 
    102 Your puzzle answer was 5073496.
    103 --- Part Two ---
    104 
    105 Your handheld device indicates that the distress signal is coming from a beacon nearby. The distress beacon is not detected by any sensor, but the distress beacon must have x and y coordinates each no lower than 0 and no larger than 4000000.
    106 
    107 To isolate the distress beacon's signal, you need to determine its tuning frequency, which can be found by multiplying its x coordinate by 4000000 and then adding its y coordinate.
    108 
    109 In the example above, the search space is smaller: instead, the x and y coordinates can each be at most 20. With this reduced search area, there is only a single position that could have a beacon: x=14, y=11. The tuning frequency for this distress beacon is 56000011.
    110 
    111 Find the only possible position for the distress beacon. What is its tuning frequency?
    112 
    113 Your puzzle answer was 13081194638237.