Skip to content

Instantly share code, notes, and snippets.

@LinusCDE
Last active January 4, 2018 16:28
Show Gist options
  • Save LinusCDE/109536a4a4b319c107c6112b6efb89d9 to your computer and use it in GitHub Desktop.
Save LinusCDE/109536a4a4b319c107c6112b6efb89d9 to your computer and use it in GitHub Desktop.
AdventOfCode 2017 day 7 part 2: Visualisation of the problem

It outputs a json-style tree of all towers/programs that are not balanced.

You need to get the value of the last tower that is unbalanced, but has no unbalanced sub-towers.

To get a good visualization do the following:

Using the input in the repo you'll get this output:

"xegshds":  # Top tower (solution of part 1)
{
    "WEIGHT": 53,
    "TOTAL_WEIGHT": 510014,  # Also contains the WEIGHT of this tower
    "upqkbq": "26244 / 101991",  # 26244 is the own weight and 101991 the total with all sub towers/programs.
    "hsdkmdv": "50286 / 101991",  # These nodes are not objects because they are balanced.
    "ggxgmci": {
        "WEIGHT": 66063,
        "TOTAL_WEIGHT": 101997,
        "nsvan": "1749 / 5988",
        "qcbfbfz": "2322 / 5988",
        "anygv": {
            "WEIGHT": 3678,
            "TOTAL_WEIGHT": 5994,
            "tghfe": "89 / 770",
            "ybzqi": "395 / 770",
            "fabacam": "305 / 776",
            "UNBLANCED": true
        },
        "gefrwix": "99 / 5988",
        "kkeafw": "1602 / 5988",
        "jepbpw": "383 / 5988",
        "UNBLANCED": true
    },
    "owjvny": "68748 / 101991",
    "gqiczm": "61 / 101991",
    "UNBLANCED": true
}

The root tower/program "xegshds" is of course unbalanced. But neither it, nor its unbalanced child are the problem. Its the tower/program that introduced the lack of balance. Following the nested towers you'll find "fabacam" to have a different total weight than its neighbors (776 instead of 770).

Remember: Since there is a total weight, this tower still has sub towers. But they are not the problem.

This gist is not supposed to tell you the answer or formula on how to solve it. It just wants to help you make your own solution and to give an idea on how I made mine. However if you insist the solution can be found here of course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment