Quick actions

cmd+k|ctrl+k

Navigation

Languages

aoc2017-day07

Snippet info

Language

Python

Visibility

public

Author

christophe.guillon.perso

Created

2017-12-08T05:38:13Z

Updated

2017-12-08T23:55:41Z

import sys
import re

input = sys.stdin.read()

lines = input.split("\n")
msuccs = {}
mwei = {}
for line in lines:
    line = re.sub("[-(),><]", "", line)
    w = line.split()
    src = w[0]
    wei = int(w[1])
    succs = w[2:]
    msuccs[src] = succs
    mwei[src] = wei

parents = {}
for root in msuccs:
    for n in msuccs[root]:
        parents[n] = root
root = list(filter(lambda x: x not in parents, msuccs))[0]
print(root)
INFO