Racing Around the Alphabet

This commit is contained in:
2023-07-18 21:38:10 +02:00
parent 7bbb5bcb4f
commit ef9eb28323

20
racingalphabet.py Normal file
View File

@@ -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))