Skip to content

Instantly share code, notes, and snippets.

@benawad
Created October 31, 2014 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benawad/ec6d5171cff30b814365 to your computer and use it in GitHub Desktop.
Save benawad/ec6d5171cff30b814365 to your computer and use it in GitHub Desktop.
Solution for problem 22 of Project Euler
alphabet = {'"':0,'A':1,'B':2,'C':3,'D':4,'E':5,'F':6,'G':7,'H':8,'I':9,'J':10,'K':11,'L':12,'M':13,'N':14,'O':15,'P':16,'Q':17,'R':18,'S':19,'T':20,'U':21,'V':22,'W':23,'X':24,'Y':25,'Z':26}
def name_value(name, pos):
sum = 0
for letter in name:
sum += alphabet[letter]
return sum * pos
names_file = open("names.txt")
names = names_file.readlines()
names_file.close()
names_list = sorted(names[0].split(','))
sum = 0;
counter = 1
for name in names_list:
sum += name_value(name, counter)
counter += 1
print sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment