Added 2017/7 part 1
This commit is contained in:
parent
4c87065d03
commit
0f6bf9563e
@ -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:
|
||||||
|
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 x in mains:
|
||||||
for line in file:
|
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))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user