adventOfCode_2023/python/Day 3/main.py

42 lines
1.1 KiB
Python

from io import open
import re
import numpy as np
# We open the txt document containing the games
input=open('input.txt','r')
# We read the text inside distinguishing by lines
text=input.readlines()
# Close the txt file to be able to work on the text without having the file open.
input.close()
del(input)
symbols=[]
matches=[]
list_text=[]
#Eliminamos los números y los puntos para obtener los dígitos diferentes/símbolos que hay
numbers=[]
for i in range(0,10):
numbers.append(str(i))
for line in text:
line=line.strip()
for element in line:
if element not in numbers and element!="." and element not in symbols:
symbols.append(element)
# Identificamos la posición en la que se encuentran los símbolos
for position,line in enumerate(text):
line=line.strip()
list_text.append(re.split('',line))
del(list_text[position][0])
del(list_text[position][-1])
for symbol in symbols:
try:
#print(symbol,position,texto[position].index(symbol))
find=position,list_text[position].index(symbol)
matches.append(find)
except ValueError:
pass