aoc-2019-c

Advent of Code 2019 Solutions in C
git clone https://git.sinitax.com/sinitax/aoc-2019-c
Log | Files | Refs | README | sfeed.txt

part1 (3448B)


      1--- Day 10: Monitoring Station ---
      2
      3You fly into the asteroid belt and reach the Ceres monitoring station.  The Elves here have an
      4emergency: they're having trouble tracking all of the asteroids and can't be sure they're safe.
      5
      6The Elves would like to build a new monitoring station in a nearby area of space; they hand you a
      7map of all of the asteroids in that region (your puzzle input).
      8
      9The map indicates whether each position is empty (.) or contains an asteroid (#).  The asteroids are
     10much smaller than they appear on the map, and every asteroid is exactly in the center of its marked
     11position.  The asteroids can be described with X,Y coordinates where X is the distance from the left
     12edge and Y is the distance from the top edge (so the top-left corner is 0,0 and the position
     13immediately to its right is 1,0).
     14
     15Your job is to figure out which asteroid would be the best place to build a new monitoring
     16station. A monitoring station can detect any asteroid to which it has direct line of sight - that
     17is, there cannot be another asteroid exactly between them. This line of sight can be at any angle,
     18not just lines aligned to the grid or diagonally. The best location is the asteroid that can
     19detect the largest number of other asteroids.
     20
     21For example, consider the following map:
     22
     23.#..#
     24.....
     25#####
     26....#
     27...##
     28
     29The best location for a new monitoring station on this map is the highlighted asteroid at 3,4
     30because it can detect 8 asteroids, more than any other location. (The only asteroid it cannot detect
     31is the one at 1,0; its view of this asteroid is blocked by the asteroid at 2,2.) All other asteroids
     32are worse locations; they can detect 7 or fewer other asteroids. Here is the number of other
     33asteroids a monitoring station on each asteroid could detect:
     34
     35.7..7
     36.....
     3767775
     38....7
     39...87
     40
     41Here is an asteroid (#) and some examples of the ways its line of sight might be blocked. If there
     42were another asteroid at the location of a capital letter, the locations marked with the
     43corresponding lowercase letter would be blocked and could not be detected:
     44
     45#.........
     46...A......
     47...B..a...
     48.EDCG....a
     49..F.c.b...
     50.....c....
     51..efd.c.gb
     52.......c..
     53....f...c.
     54...e..d..c
     55
     56Here are some larger examples:
     57
     58
     59 - Best is 5,8 with 33 other asteroids detected:
     60
     61......#.#.
     62#..#.#....
     63..#######.
     64.#.#.###..
     65.#..#.....
     66..#....#.#
     67#..#....#.
     68.##.#..###
     69##...#..#.
     70.#....####
     71
     72
     73 - Best is 1,2 with 35 other asteroids detected:
     74
     75#.#...#.#.
     76.###....#.
     77.#....#...
     78##.#.#.#.#
     79....#.#.#.
     80.##..###.#
     81..#...##..
     82..##....##
     83......#...
     84.####.###.
     85
     86
     87 - Best is 6,3 with 41 other asteroids detected:
     88
     89.#..#..###
     90####.###.#
     91....###.#.
     92..###.##.#
     93##.##.#.#.
     94....###..#
     95..#.#..#.#
     96#..#.#.###
     97.##...##.#
     98.....#.#..
     99
    100
    101 - Best is 11,13 with 210 other asteroids detected:
    102
    103.#..##.###...#######
    104##.############..##.
    105.#.######.########.#
    106.###.#######.####.#.
    107#####.##.#.##.###.##
    108..#####..#.#########
    109####################
    110#.####....###.#.#.##
    111##.#################
    112#####.##.###..####..
    113..######..##.#######
    114####.##.####...##..#
    115.#####..#.######.###
    116##...#.##########...
    117#.##########.#######
    118.####.#.###.###.#.##
    119....##.##.###..#####
    120.#.#.###########.###
    121#.#.#.#####.####.###
    122###.##.####.##.#..##
    123
    124
    125
    126Find the best location for a new monitoring station.  How many other asteroids can be detected from
    127that location?
    128
    129