AdventOfCode/2017/24/solution.py

69 lines
1.6 KiB
Python

#!/bin/python3
import sys,re
from copy import deepcopy
from pprint import pprint
sys.path.insert(0, '../../')
from fred import list2int, lprint,get_re
input_f = 'test'
part = 1
log = True
#########################################
# #
# Part 1 #
# #
#########################################
def find_match(comp:list,match:str,result:list):
i_match = get_re(r"^(\d+)\/(\d+)$",match)
#print(comp,match)
comp = [i for i in comp if i != match]
#print(comp,result)
for i in result:
try:
comp = [j for j in comp if j != i]
except:
print(i,'cant be removed from',j)
for j in comp:
j_match = get_re(r"^(\d+)\/(\d+)$",j)
#print(match,j)
#input()
if i_match.group(2) == j_match.group(1) or i_match.group(2) == j_match.group(2):
result.append(j)
find_match(comp[:],match,result[:])
return result
if part == 1:
components = []
with open(input_f) as file:
for line in file:
components.append(line.rstrip())
lprint(components,log)
original_comp = deepcopy(components)
pairs = []
result = []
for i in components[:]:
print(i)
if i[0] == '0':
result.append(find_match(original_comp,i,[i]))
pprint(result)
#nput()
#lprint(pairs,log)
#########################################
# #
# Part 2 #
# #
#########################################
if part == 2:
exit()