04
This commit is contained in:
43
04/04-2.py
Normal file
43
04/04-2.py
Normal file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
file = "./input.txt"
|
||||
#file = "./ex.txt"
|
||||
from time import time
|
||||
import re
|
||||
start_time = time()
|
||||
|
||||
def caesar_chiffre(text, verschiebung):
|
||||
ergebnis = ""
|
||||
for char in text:
|
||||
if char.isalpha():
|
||||
ascii_offset = 65 if char.isupper() else 97
|
||||
verschobener_ascii = (ord(char) - ascii_offset + verschiebung) % 26 + ascii_offset
|
||||
ergebnis += chr(verschobener_ascii)
|
||||
else:
|
||||
ergebnis += char
|
||||
return ergebnis
|
||||
|
||||
def de_chiffre(txt:str, rot:int)-> str:
|
||||
result = []
|
||||
txt = txt.split("-")
|
||||
for part in txt:
|
||||
result.append(caesar_chiffre(part, rot))
|
||||
return " ".join(result)
|
||||
|
||||
if __name__ == "__main__":
|
||||
sol = 0
|
||||
input_file = open(file, "r")
|
||||
for line in input_file:
|
||||
line = line.strip()
|
||||
if line == "":
|
||||
continue
|
||||
else:
|
||||
pat = r'^([a-z-]+)-(\d+)\[([a-z]+)\]$'
|
||||
match = re.match(pat,line)
|
||||
out_txt = de_chiffre(match.group(1), int(match.group(2)))
|
||||
if "north" in out_txt:
|
||||
print(f"{out_txt} - {match.group(2)}")
|
||||
input_file.close()
|
||||
|
||||
print(f'Runtime: {time()-start_time:.4f} s')
|
||||
Reference in New Issue
Block a user