euler/python/e022.py

18 lines
508 B
Python
Raw Normal View History

2019-07-16 04:11:49 +02:00
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()))