1
0

aoc 2017 - day 7

This commit is contained in:
2020-01-15 02:55:30 +01:00
parent 4da4c47915
commit 4977278175
5 changed files with 1200 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
#!/usr/bin/env python3
import aoc
def parse_line(line: str):
childs = list()
if ' -> ' in line:
split1 = line.split(' -> ')
childs = list(map(lambda x: x.strip(), split1[1].strip().split(',')))
line = split1[0]
line = line.strip()
line = line.replace('(', '').replace(')', '')
split2 = line.split(' ')
name = split2[0].strip()
weight = int(split2[1].strip())
return name, weight, childs
rawinput = aoc.read_input(7)
data = list(map(lambda x: parse_line(x), rawinput.splitlines()))
rnodes = list(map(lambda x: x[0], data))
for datum in data:
for xnode in datum[2]:
rnodes.remove(xnode)
assert len(rnodes) == 1
print(rnodes[0])