2024-11-16 08:05:16 +01:00
|
|
|
#!/bin/python3
|
2024-11-22 10:45:38 +01:00
|
|
|
import sys, re
|
2024-11-16 08:05:16 +01:00
|
|
|
from pprint import pprint
|
|
|
|
|
2024-11-22 10:45:38 +01:00
|
|
|
input_f = 'test'
|
|
|
|
part = 2
|
2024-11-16 08:05:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
#########################################
|
|
|
|
# #
|
|
|
|
# Part 1 #
|
|
|
|
# #
|
|
|
|
#########################################
|
2024-11-22 10:45:38 +01:00
|
|
|
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))
|
|
|
|
|
|
|
|
for x in mains:
|
|
|
|
if x not in children:
|
|
|
|
print(x)
|
2024-11-16 08:05:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#########################################
|
|
|
|
# #
|
|
|
|
# Part 2 #
|
|
|
|
# #
|
|
|
|
#########################################
|
2024-11-22 10:45:38 +01:00
|
|
|
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))
|
|
|
|
|