Adopted new convention from template
This commit is contained in:
parent
a9b11d4e0d
commit
af245d7946
@ -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()}")
|
||||
|
Loading…
x
Reference in New Issue
Block a user