Added 2017/7 part 1

This commit is contained in:
FrederikBaerentsen 2024-11-22 10:45:38 +01:00
parent 4c87065d03
commit 0f6bf9563e

View File

@ -1,8 +1,9 @@
#!/bin/python3 #!/bin/python3
import sys import sys, re
from pprint import pprint 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 # # Part 1 #
# # # #
######################################### #########################################
if part == 1:
with open(input_f) as file: children = []
mains = []
with open(input_f)as file:
for line in 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))
for x in mains:
if x not in children:
print(x)
@ -22,3 +36,17 @@ with open(input_f) as file:
# Part 2 # # 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))