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

part1 (4560B)


      1--- Day 12: Subterranean Sustainability ---
      2
      3The year 518 is significantly more underground than your history books implied.  Either that, or
      4you've arrived in a vast cavern network under the North Pole.
      5
      6After exploring a little, you discover a long tunnel that contains a row of small pots as far as you
      7can see to your left and right.  A few of them contain plants - someone is trying to grow things in
      8these geothermally-heated caves.
      9
     10The pots are numbered, with 0 in front of you.  To the left, the pots are numbered -1, -2, -3, and
     11so on; to the right, 1, 2, 3.... Your puzzle input contains a list of pots from 0 to the right and
     12whether they do (#) or do not (.) currently contain a plant, the initial state. (No other pots
     13currently contain plants.) For example, an initial state of #..##.... indicates that pots 0, 3, and
     144 currently contain plants.
     15
     16Your puzzle input also contains some notes you find on a nearby table: someone has been trying to
     17figure out how these plants spread to nearby pots.  Based on the notes, for each generation of
     18plants, a given pot has or does not have a plant based on whether that pot (and the two pots on
     19either side of it) had a plant in the last generation. These are written as LLCRR => N, where L are
     20pots to the left, C is the current pot being considered, R are the pots to the right, and N is
     21whether the current pot will have a plant in the next generation. For example:
     22
     23
     24 - A note like ..#.. => . means that a pot that contains a plant but with no plants within two pots
     25of it will not have a plant in it during the next generation.
     26
     27 - A note like ##.## => . means that an empty pot with two plants on each side of it will remain
     28empty in the next generation.
     29
     30 - A note like .##.# => # means that a pot has a plant in a given generation if, in the previous
     31generation, there were plants in that pot, the one immediately to the left, and the one two pots to
     32the right, but not in the ones immediately to the right and two to the left.
     33
     34
     35It's not clear what these plants are for, but you're sure it's important, so you'd like to make sure
     36the current configuration of plants is sustainable by determining what will happen after 20
     37generations.
     38
     39For example, given the following input:
     40
     41initial state: #..#.#..##......###...###
     42
     43...## => #
     44..#.. => #
     45.#... => #
     46.#.#. => #
     47.#.## => #
     48.##.. => #
     49.#### => #
     50#.#.# => #
     51#.### => #
     52##.#. => #
     53##.## => #
     54###.. => #
     55###.# => #
     56####. => #
     57
     58For brevity, in this example, only the combinations which do produce a plant are listed. (Your input
     59includes all possible combinations.) Then, the next 20 generations will look like this:
     60
     61                 1         2         3     
     62       0         0         0         0     
     63 0: ...#..#.#..##......###...###...........
     64 1: ...#...#....#.....#..#..#..#...........
     65 2: ...##..##...##....#..#..#..##..........
     66 3: ..#.#...#..#.#....#..#..#...#..........
     67 4: ...#.#..#...#.#...#..#..##..##.........
     68 5: ....#...##...#.#..#..#...#...#.........
     69 6: ....##.#.#....#...#..##..##..##........
     70 7: ...#..###.#...##..#...#...#...#........
     71 8: ...#....##.#.#.#..##..##..##..##.......
     72 9: ...##..#..#####....#...#...#...#.......
     7310: ..#.#..#...#.##....##..##..##..##......
     7411: ...#...##...#.#...#.#...#...#...#......
     7512: ...##.#.#....#.#...#.#..##..##..##.....
     7613: ..#..###.#....#.#...#....#...#...#.....
     7714: ..#....##.#....#.#..##...##..##..##....
     7815: ..##..#..#.#....#....#..#.#...#...#....
     7916: .#.#..#...#.#...##...#...#.#..##..##...
     8017: ..#...##...#.#.#.#...##...#....#...#...
     8118: ..##.#.#....#####.#.#.#...##...##..##..
     8219: .#..###.#..#.#.#######.#.#.#..#.#...#..
     8320: .#....##....#####...#######....#.#..##.
     84
     85The generation is shown along the left, where 0 is the initial state.  The pot numbers are shown
     86along the top, where 0 labels the center pot, negative-numbered pots extend to the left, and
     87positive pots extend toward the right. Remember, the initial state begins at pot 0, which is not the
     88leftmost pot used in this example.
     89
     90After one generation, only seven plants remain.  The one in pot 0 matched the rule looking for
     91..#.., the one in pot 4 matched the rule looking for .#.#., pot 9 matched .##.., and so on.
     92
     93In this example, after 20 generations, the pots shown as # contain plants, the furthest left of
     94which is pot -2, and the furthest right of which is pot 34. Adding up all the numbers of
     95plant-containing pots after the 20th generation produces 325.
     96
     97After 20 generations, what is the sum of the numbers of all pots which contain a plant?
     98
     99