Skip to content

Commit

Permalink
Adds Python 022
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankKair committed Dec 6, 2018
1 parent 434f7a4 commit c86e864
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/022/p022.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env python3
import os


def load_names():
file_path = os.path.join(os.path.dirname(__file__), 'p022_names.txt')
with open(file_path) as file_handle:
names_list = file_handle.read().replace('\"', '').split(',')
return sorted(names_list)


def name_score(name):
return sum(ord(char) - 64 for char in name)


def solve():
total_score = 0
names_list = load_names()
for index, name in enumerate(names_list):
score = name_score(name) * (index + 1)
total_score += score
return total_score


if __name__ == '__main__':
result = solve()
print(result)

0 comments on commit c86e864

Please sign in to comment.