03-1 Anfang

This commit is contained in:
2023-12-03 12:08:11 +01:00
parent 7a1466a9c4
commit 0d7822cd80
3 changed files with 199 additions and 0 deletions

49
03/03-1.py Normal file
View File

@@ -0,0 +1,49 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
part_sum = 0
matrix = []
input_file = open("input-ex.txt", "r")
for line in input_file:
matrix.append(line.strip())
input_file.close()
zeilen = len(matrix)
spalten = len(matrix[0])
num_list = []
for z in range(zeilen):
pre_is_num = False
num_start, num_end = 0, 0
num = ""
for s in range(spalten):
if matrix[z][s].isdigit() and s == spalten-1:
num += matrix[z][s]
if num_start == 0:
num_start = s
num_end = s
num_list.append([int(num), z, num_start, num_end])
elif pre_is_num and not matrix[z][s].isdigit():
num_end = s-1
num_list.append([int(num), z, num_start, num_end])
pre_is_num = False
elif not pre_is_num and matrix[z][s].isdigit():
num = matrix[z][s]
num_start = s
pre_is_num = True
elif pre_is_num:
num += matrix[z][s]
# Matrix-Ausgabe
for x in matrix:
print(x)
print(f"Zeilen: {zeilen}")
print(f"Spalten: {spalten}")
print()
# num_list ausgabe
for n in num_list:
print(n)