Using names.txt a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score.

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.

What is the total of all the name scores in the file?


In [3]:
!wget https://projecteuler.net/project/names.txt


--2014-03-29 16:57:13--  https://projecteuler.net/project/names.txt
Resolving projecteuler.net (projecteuler.net)... 95.142.153.162
Connecting to projecteuler.net (projecteuler.net)|95.142.153.162|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 46447 (45K) [text/plain]
Saving to: ‘names.txt’

100%[======================================>] 46.447       181KB/s   in 0,3s   

2014-03-29 16:57:14 (181 KB/s) - ‘names.txt’ saved [46447/46447]


In [9]:
with open('names.txt') as f:
    names_one_row = next(f)

In [22]:
names = sorted([n.replace('"','').lower() for n  in names_one_row.split(',')])

In [26]:
print(sum( i*sum( ord(c)-96 for c in name) for i, name in enumerate(names, start=1)))


871198282