From af245d79461876680833f1389db2c38f6d5c8944 Mon Sep 17 00:00:00 2001 From: daviddoji Date: Wed, 28 Sep 2022 19:34:26 +0200 Subject: [PATCH] Adopted new convention from template --- src/Python/Problems001-050/Problem022.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Python/Problems001-050/Problem022.py b/src/Python/Problems001-050/Problem022.py index 8b83b51..4fbc765 100644 --- a/src/Python/Problems001-050/Problem022.py +++ b/src/Python/Problems001-050/Problem022.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python """ Created on 31 Dec 2018 @@ -24,20 +24,21 @@ def compute(): For example, when the list is sorted into alphabetical order, COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, - COLIN would obtain a score of 938 × 53 = 49714. + COLIN would obtain a score of 938 x 53 = 49714. What is the total of all the name scores in the file? """ + file = Path("../files/Problem22.txt") with open(file, "r") as f: names = sorted(f.read().replace('"', "").split(",")) - result = 0 + ans = 0 for idx, name in enumerate(names, 1): - result += sum(ord(c) - 64 for c in name) * idx - return result + ans += sum(ord(char) - 64 for char in name) * idx + + return ans if __name__ == "__main__": - - print(f"Result for Problem 22: {compute()}") + print(f"Result for Problem 22 is {compute()}")