Names Scoresproblem 22
Using Names.txt (Right click and ' Save link/target as ... '), a 46K text file containing over Five-thousand first names, beg In by sorting it into alphabetical order. Then working out of the alphabetical value for each name, multiply this value by it alphabetical position in the list to OBT Ain a name score.
For example, when the list is sorted to alphabetical order, COLIN, which is worth 3 + + + + 9 + = 938t H name in the list. So, COLIN would obtain a score of 938x53 = 49714.
What's the total of the "scores in the file?"
Go to the "thread for Problem" in the forum.
Python Code:
def func (name): result=0 for i in range (0,len (name)): Result+=ord (Name[i])-ord (' A ') +1 return Resultfor Line in open (' P022_names.txt ', ' R '): line.strip (' \ n ') line=line.replace (R ' "', ') lst=line.split (', ') lst=sorted (LST) result=0for I in range (0,len (LST)): Result+=func (Lst[i]) * (i+1) print (result)
Time: <1s
Euler program (python) problem 22