From ef9eb28323a5c545b2a5c72cd05c184173bd3d8c Mon Sep 17 00:00:00 2001 From: Jethro Stapelbroek Date: Tue, 18 Jul 2023 21:38:10 +0200 Subject: [PATCH] Racing Around the Alphabet --- racingalphabet.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 racingalphabet.py diff --git a/racingalphabet.py b/racingalphabet.py new file mode 100644 index 0000000..bf46a28 --- /dev/null +++ b/racingalphabet.py @@ -0,0 +1,20 @@ +import math + + +def calculate_distance(aphorism: str) -> int: + tokens = "ABCDEFGHIJKLMNOPQRSTUVWXYZ '" + prev_s = aphorism[0] + total_distance = 0 + for s in aphorism: + current_distance = (tokens.index(prev_s) - tokens.index(s)) % 28 + if current_distance > 14: + current_distance = 28 - current_distance + prev_s = s + total_distance += current_distance + return 60 * math.pi / 28 * total_distance + + +n = int(input()) +for _ in range(n): + aphorism = input() + print(calculate_distance(aphorism) / 15 + len(aphorism))