From 160b5a2f5bde26d2685dc287945ef74c5ddb052e Mon Sep 17 00:00:00 2001 From: Lukas Baumann Date: Wed, 17 Feb 2021 12:29:35 +0100 Subject: [PATCH] Create 3.py --- 15/c/3.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 15/c/3.py diff --git a/15/c/3.py b/15/c/3.py new file mode 100644 index 0000000..a1e2958 --- /dev/null +++ b/15/c/3.py @@ -0,0 +1,30 @@ +def move(txt, x): + txt = [ord(i) for i in txt] + for i in range(len(txt)): + if ord("A") <= txt[i] <= ord("Z"): + txt[i] += x + txt[i] = (txt[i] - ord("A")) % 26 + ord("A") + return "".join ([chr(i) for i in txt]) + +def goodness(txt): + res = 0 + for i in txt: + if i.isalpha(): + res += letterGoodness[ord(i)-ord("A")] + return res + +def best_match(txt): + best = ["", 0] + + for i in range(26): + txt = move(txt, 1) + gdnss = goodness(txt) + if gdnss > best[1]: + best[0] = txt + best[1] = gdnss + + return best[0] + +print(best_match(input())) + +