24 anfang

This commit is contained in:
2024-12-24 15:17:04 +01:00
parent 27083bf502
commit 1756e53efc
4 changed files with 406 additions and 0 deletions

36
24/24-01.py Normal file
View File

@@ -0,0 +1,36 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from time import time
import re
start_time = time()
# file = "./input.txt"
file = "./ex-small.txt"
# file = "./ex-big.txt"
def read_and_parse(input_file: str) -> tuple[dict[str:int], list[tuple[str, str, str, str]]]:
result_dict = {}
with open(input_file, 'r') as d:
datei = d.read()
pat_dict = r'(.+)\: +(\d)'
pat_list = r'(.+) +(.+) +(.+) +\-\> +(.+)'
match_d = re.findall(pat_dict, datei)
# print(match_d)
for d in match_d:
result_dict[d[0]] = int(d[1])
match_l = re.findall(pat_list, datei)
# print(match_l)
return result_dict, match_l
if __name__ == "__main__":
in_dict, in_list = read_and_parse(file)
print(in_dict)
print(in_list)
print(f'Runtime: {time() - start_time:.2f} s')