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 (2304B)


      1--- Day 24: Planet of Discord ---
      2
      3You land on Eris, your last stop before reaching Santa.  As soon as you do, your sensors start
      4picking up strange life forms moving around: Eris is infested with bugs! With an over 24-hour
      5roundtrip for messages between you and Earth, you'll have to deal with this problem on your own.
      6
      7Eris isn't a very large place; a scan of the entire area fits into a 5x5 grid (your puzzle input).
      8The scan shows bugs (#) and empty spaces (.).
      9
     10Each minute, The bugs live and die based on the number of bugs in the four adjacent tiles:
     11
     12
     13 - A bug dies (becoming an empty space) unless there is exactly one bug adjacent to it.
     14
     15 - An empty space becomes infested with a bug if exactly one or two bugs are adjacent to it.
     16
     17
     18Otherwise, a bug or empty space remains the same.  (Tiles on the edges of the grid have fewer than
     19four adjacent tiles; the missing tiles count as empty space.) This process happens in every location
     20simultaneously; that is, within the same minute, the number of adjacent bugs is counted for every
     21tile first, and then the tiles are updated.
     22
     23Here are the first few minutes of an example scenario:
     24
     25Initial state:
     26....#
     27#..#.
     28#..##
     29..#..
     30#....
     31
     32After 1 minute:
     33#..#.
     34####.
     35###.#
     36##.##
     37.##..
     38
     39After 2 minutes:
     40#####
     41....#
     42....#
     43...#.
     44#.###
     45
     46After 3 minutes:
     47#....
     48####.
     49...##
     50#.##.
     51.##.#
     52
     53After 4 minutes:
     54####.
     55....#
     56##..#
     57.....
     58##...
     59
     60To understand the nature of the bugs, watch for the first time a layout of bugs and empty spaces
     61matches any previous layout. In the example above, the first layout to appear twice is:
     62
     63.....
     64.....
     65.....
     66#....
     67.#...
     68
     69To calculate the biodiversity rating for this layout, consider each tile left-to-right in the top
     70row, then left-to-right in the second row, and so on. Each of these tiles is worth biodiversity
     71points equal to increasing powers of two: 1, 2, 4, 8, 16, 32, and so on.  Add up the biodiversity
     72points for tiles with bugs; in this example, the 16th tile (32768 points) and 22nd tile (2097152
     73points) have bugs, a total biodiversity rating of 2129920.
     74
     75What is the biodiversity rating for the first layout that appears twice?
     76
     77