From c132d251cc7d60596213e542c0d8d766f40e5804 Mon Sep 17 00:00:00 2001 From: Jaime9070 Date: Sat, 9 Dec 2023 14:50:57 +0100 Subject: [PATCH] day 3 python part 1 --- python/Day 3/main.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 python/Day 3/main.py diff --git a/python/Day 3/main.py b/python/Day 3/main.py new file mode 100644 index 0000000..98774dc --- /dev/null +++ b/python/Day 3/main.py @@ -0,0 +1,42 @@ +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 \ No newline at end of file