From 0f6bf9563ef19b08127362cd6c6156e39f422987 Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Fri, 22 Nov 2024 10:45:38 +0100 Subject: [PATCH] Added 2017/7 part 1 --- 2017/07/solution.py | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) 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