18 lines
508 B
Python
18 lines
508 B
Python
|
def get_score_for_name(name):
|
||
|
return sum([ord(c) - ord('A') + 1 for c in name if not c == '"'])
|
||
|
|
||
|
|
||
|
def euler_022():
|
||
|
with open('../txt/EulerProblem022.txt', 'r') as f:
|
||
|
names = f.read().split(',')
|
||
|
names.sort()
|
||
|
s = sum([(i + 1) * get_score_for_name(name)
|
||
|
for i, name in enumerate(names)])
|
||
|
return s
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
assert(get_score_for_name('COLIN') == 53)
|
||
|
assert(euler_022() == 871198282)
|
||
|
print("e022.py: {}".format(euler_022()))
|