Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Solution to Day 7: Recursive Circus - part1
#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