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


      1--- Day 5: Alchemical Reduction ---
      2
      3You've managed to sneak in to the prototype suit manufacturing lab.  The Elves are making decent
      4progress, but are still struggling with the suit's size reduction capabilities.
      5
      6While the very latest in 1518 alchemical technology might have solved their problem eventually, you
      7can do better.  You scan the chemical composition of the suit's material and discover that it is
      8formed by extremely long polymers (one of which is available as your puzzle input).
      9
     10The polymer is formed by smaller units which, when triggered, react with each other such that two
     11adjacent units of the same type and opposite polarity are destroyed. Units' types are represented by
     12letters; units' polarity is represented by capitalization.  For instance, r and R are units with the
     13same type but opposite polarity, whereas r and s are entirely different types and do not react.
     14
     15For example:
     16
     17
     18 - In aA, a and A react, leaving nothing behind.
     19
     20 - In abBA, bB destroys itself, leaving aA.  As above, this then destroys itself, leaving nothing.
     21
     22 - In abAB, no two adjacent units are of the same type, and so nothing happens.
     23
     24 - In aabAAB, even though aa and AA are of the same type, their polarities match, and so nothing
     25happens.
     26
     27
     28Now, consider a larger example, dabAcCaCBAcCcaDA:
     29
     30dabAcCaCBAcCcaDA  The first 'cC' is removed.
     31dabAaCBAcCcaDA    This creates 'Aa', which is removed.
     32dabCBAcCcaDA      Either 'cC' or 'Cc' are removed (the result is the same).
     33dabCBAcaDA        No further actions can be taken.
     34
     35After all possible reactions, the resulting polymer contains 10 units.
     36
     37How many units remain after fully reacting the polymer you scanned? (Note: in this puzzle and
     38others, the input is large; if you copy/paste your input, make sure you get the whole thing.)
     39
     40