aoc-2018-python

Advent of Code 2018 Solutions in Python
git clone https://git.sinitax.com/sinitax/aoc-2018-python
Log | Files | Refs | README | sfeed.txt

part2 (3485B)


      1--- Part Two ---
      2
      3Once you give them the coordinates, the Elves quickly deploy an Instant Monitoring Station to the
      4location and discover the worst: there are simply too many asteroids.
      5
      6The only solution is complete vaporization by giant laser.
      7
      8Fortunately, in addition to an asteroid scanner, the new monitoring station also comes equipped with
      9a giant rotating laser perfect for vaporizing asteroids. The laser starts by pointing
     10up and always rotates clockwise, vaporizing any asteroid it hits.
     11
     12If multiple asteroids are exactly in line with the station, the laser only has enough power to
     13vaporize one of them before continuing its rotation. In other words, the same asteroids that can be
     14detected can be vaporized, but if vaporizing one asteroid makes another one detectable, the
     15newly-detected asteroid won't be vaporized until the laser has returned to the same position by
     16rotating a full 360 degrees.
     17
     18For example, consider the following map, where the asteroid with the new monitoring station (and
     19laser) is marked X:
     20
     21.#....#####...#..
     22##...##.#####..##
     23##...#...#.#####.
     24..#.....X...###..
     25..#.#.....#....##
     26
     27The first nine asteroids to get vaporized, in order, would be:
     28
     29.#....###24...#..
     30##...##.13#67..9#
     31##...#...5.8####.
     32..#.....X...###..
     33..#.#.....#....##
     34
     35Note that some asteroids (the ones behind the asteroids marked 1, 5, and 7) won't have a chance to
     36be vaporized until the next full rotation.  The laser continues rotating; the next nine to be
     37vaporized are:
     38
     39.#....###.....#..
     40##...##...#.....#
     41##...#......1234.
     42..#.....X...5##..
     43..#.9.....8....76
     44
     45The next nine to be vaporized are then:
     46
     47.8....###.....#..
     4856...9#...#.....#
     4934...7...........
     50..2.....X....##..
     51..1..............
     52
     53Finally, the laser completes its first full rotation (1 through 3), a second rotation (4 through 8),
     54and vaporizes the last asteroid (9) partway through its third rotation:
     55
     56......234.....6..
     57......1...5.....7
     58.................
     59........X....89..
     60.................
     61
     62In the large example above (the one with the best monitoring station location at 11,13):
     63
     64
     65 - The 1st asteroid to be vaporized is at 11,12.
     66
     67 - The 2nd asteroid to be vaporized is at 12,1.
     68
     69 - The 3rd asteroid to be vaporized is at 12,2.
     70
     71 - The 10th asteroid to be vaporized is at 12,8.
     72
     73 - The 20th asteroid to be vaporized is at 16,0.
     74
     75 - The 50th asteroid to be vaporized is at 16,9.
     76
     77 - The 100th asteroid to be vaporized is at 10,16.
     78
     79 - The 199th asteroid to be vaporized is at 9,6.
     80
     81 - The 200th asteroid to be vaporized is at 8,2.
     82
     83 - The 201st asteroid to be vaporized is at 10,9.
     84
     85 - The 299th and final asteroid to be vaporized is at 11,1.
     86
     87
     88The Elves are placing bets on which will be the 200th asteroid to be vaporized.  Win the bet by
     89determining which asteroid that will be; what do you get if you multiply its X coordinate by 100 and
     90then add its Y coordinate? (For example, 8,2 becomes 802.)
     91
     92