-
-
Save pawlos/e9fdd3c06d5b75128eabf015305323b6 to your computer and use it in GitHub Desktop.
Solution to Day 7: Recursive Circus - part1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#aoc_d7.py | |
inp = open('input_d7.txt','r').readlines() | |
#["pbga (66)","xhth (57)","ebii (61)","havc (66)","ktlj (57)","fwft (72) -> ktlj, cntj, xhth","qoyq (66)","padx (45) -> pbga, havc, qoyq","tknk (41) -> ugml, padx, fwft","jptl (61)","ugml (68) -> gyxo, ebii, jptl","gyxo (61)","cntj (57)"] | |
top = '' | |
for item in inp: | |
if "->" in item: | |
items = item.split("->") | |
name = items[0][0:items[0].index('(')].strip() | |
children = [i.strip() for i in items[1].split(',')] | |
print top, name, children, top in children | |
if top == '': | |
top = name | |
if top in children: | |
top = name | |
print top |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment