-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem 22.py
78 lines (72 loc) · 1.69 KB
/
Problem 22.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 13 19:04:55 2012
@author: Lucas
"""
def namescore(word):
score = 0
for ltr in word:
if ltr == "A":
score += 1
elif ltr == "B":
score += 2
elif ltr == "C":
score += 3
elif ltr == "D":
score += 4
elif ltr == "E":
score += 5
elif ltr == "F":
score += 6
elif ltr == "G":
score += 7
elif ltr == "H":
score += 8
elif ltr == "I":
score += 9
elif ltr == "J":
score += 10
elif ltr == "K":
score += 11
elif ltr == "L":
score += 12
elif ltr == "M":
score += 13
elif ltr == "N":
score += 14
elif ltr == "O":
score += 15
elif ltr == "P":
score += 16
elif ltr == "Q":
score += 17
elif ltr == "R":
score += 18
elif ltr == "S":
score += 19
elif ltr == "T":
score += 20
elif ltr == "U":
score += 21
elif ltr == "V":
score += 22
elif ltr == "W":
score += 23
elif ltr == "X":
score += 24
elif ltr == "Y":
score += 25
elif ltr == "Z":
score += 26
return score
data = ([])
import csv
with open('names.txt', 'rb') as f:
reader = csv.reader(f)
for row in reader:
data = row
data.sort()
answer = 0
for i in xrange(0,len(data)):
answer += namescore(data[i]) * (i+1)
print answer