2024-11-29 22:12:47 +01:00
|
|
|
#!/bin/python3
|
|
|
|
import sys,re
|
2024-11-30 23:15:29 +01:00
|
|
|
from copy import deepcopy
|
2024-11-29 22:12:47 +01:00
|
|
|
from pprint import pprint
|
|
|
|
sys.path.insert(0, '../../')
|
2024-11-30 20:13:48 +01:00
|
|
|
from fred import list2int, lprint,get_re
|
2024-11-29 22:12:47 +01:00
|
|
|
|
|
|
|
input_f = 'test'
|
|
|
|
|
|
|
|
part = 1
|
2024-11-30 20:13:48 +01:00
|
|
|
log = True
|
2024-11-29 22:12:47 +01:00
|
|
|
#########################################
|
|
|
|
# #
|
|
|
|
# Part 1 #
|
|
|
|
# #
|
|
|
|
#########################################
|
|
|
|
|
2024-11-30 23:15:29 +01:00
|
|
|
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
|
|
|
|
|
2024-11-29 22:12:47 +01:00
|
|
|
if part == 1:
|
2024-11-30 20:13:48 +01:00
|
|
|
components = []
|
2024-11-29 22:12:47 +01:00
|
|
|
with open(input_f) as file:
|
|
|
|
for line in file:
|
2024-11-30 20:13:48 +01:00
|
|
|
components.append(line.rstrip())
|
|
|
|
|
|
|
|
lprint(components,log)
|
2024-11-30 23:15:29 +01:00
|
|
|
original_comp = deepcopy(components)
|
2024-11-30 20:13:48 +01:00
|
|
|
pairs = []
|
2024-11-30 23:15:29 +01:00
|
|
|
result = []
|
|
|
|
|
|
|
|
for i in components[:]:
|
|
|
|
print(i)
|
|
|
|
if i[0] == '0':
|
|
|
|
result.append(find_match(original_comp,i,[i]))
|
|
|
|
|
2024-11-30 20:13:48 +01:00
|
|
|
|
2024-11-30 23:15:29 +01:00
|
|
|
pprint(result)
|
|
|
|
#nput()
|
|
|
|
#lprint(pairs,log)
|
2024-11-30 20:13:48 +01:00
|
|
|
|
2024-11-29 22:12:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#########################################
|
|
|
|
# #
|
|
|
|
# Part 2 #
|
|
|
|
# #
|
|
|
|
#########################################
|
|
|
|
if part == 2:
|
|
|
|
exit()
|