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


      1--- Day 8: Memory Maneuver ---
      2
      3The sleigh is much easier to pull than you'd expect for something its weight. Unfortunately, neither
      4you nor the Elves know which way the North Pole is from here.
      5
      6You check your wrist device for anything that might help.  It seems to have some kind of navigation
      7system!  Activating the navigation system produces more bad news: "Failed to start navigation
      8system. Could not read software license file."
      9
     10The navigation system's license file consists of a list of numbers (your puzzle input).  The numbers
     11define a data structure which, when processed, produces some kind of tree that can be used to
     12calculate the license number.
     13
     14The tree is made up of nodes; a single, outermost node forms the tree's root, and it contains all
     15other nodes in the tree (or contains nodes that contain nodes, and so on).
     16
     17Specifically, a node consists of:
     18
     19
     20 - A header, which is always exactly two numbers:
     21
     22 - The quantity of child nodes.
     23
     24 - The quantity of metadata entries.
     25
     26
     27 - Zero or more child nodes (as specified in the header).
     28
     29 - One or more metadata entries (as specified in the header).
     30
     31
     32
     33Each child node is itself a node that has its own header, child nodes, and metadata. For example:
     34
     352 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2
     36A----------------------------------
     37    B----------- C-----------
     38                     D-----
     39
     40In this example, each node of the tree is also marked with an underline starting with a letter for
     41easier identification. In it, there are four nodes:
     42
     43
     44 - A, which has 2 child nodes (B, C) and 3 metadata entries (1, 1, 2).
     45
     46 - B, which has 0 child nodes and 3 metadata entries (10, 11, 12).
     47
     48 - C, which has 1 child node (D) and 1 metadata entry (2).
     49
     50 - D, which has 0 child nodes and 1 metadata entry (99).
     51
     52
     53The first check done on the license file is to simply add up all of the metadata entries.  In this
     54example, that sum is 1+1+2+10+11+12+2+99=138.
     55
     56What is the sum of all metadata entries?
     57
     58