diff --git a/2017/07/solution.py b/2017/07/solution.py index e9056ce..0167b7b 100644 --- a/2017/07/solution.py +++ b/2017/07/solution.py @@ -1,8 +1,9 @@ #!/bin/python3 -import sys +import sys, re from pprint import pprint -input_f = sys.argv[1] +input_f = 'test' +part = 2 ######################################### @@ -10,10 +11,23 @@ input_f = sys.argv[1] # Part 1 # # # ######################################### +if part == 1: + children = [] + mains = [] + with open(input_f)as file: + for line in file: + l = line.rstrip() + if '->' in l: + x = l.split('->') + for i in x[1].split(','): + children.append(i.strip()) + match = re.match(r"^(\S+)",x[0]) + if match: + mains.append(match.group(1)) -with open(input_f) as file: - for line in file: - + for x in mains: + if x not in children: + print(x) @@ -22,3 +36,17 @@ with open(input_f) as file: # Part 2 # # # ######################################### +if part == 2: + children = [] + mains = [] + with open(input_f)as file: + for line in file: + l = line.rstrip() + if '->' in l: + x = l.split('->') + for i in x[1].split(','): + children.append(i.strip()) + match = re.match(r"^(\S+)",x[0]) + if match: + mains.append(match.group(1)) + \ No newline at end of file