-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem_022.py
More file actions
48 lines (39 loc) · 1.18 KB
/
Copy pathproblem_022.py
File metadata and controls
48 lines (39 loc) · 1.18 KB
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
# Date: 2020.07.19
# Answer: 871198282
import string
alphabet_string = string.ascii_uppercase
alphabet_list = list(alphabet_string)
def input_names(path):
list_from_file = []
# input data from file into array
with open(path) as data:
for cnt, line in enumerate(data):
list_from_file=line.split(",")
return list_from_file
def get_letter_score(letter):
return alphabet_list.index(letter)+1
def get_name_value(name):
name_value = 0
for i in name:
name_value += get_letter_score(i)
#print(letter_score,name_value,position)# alphabet_list.index(i))
return name_value
def get_name_score(name,position):
return get_name_value(name)*position
def get_total_score(list_of_names):
sum = 0
for cnt,name in enumerate(list_of_names):
#print(cnt,name)
sum += get_name_score(name.strip('"'),cnt+1)
return sum
#print(get_total_score(names))
#print(get_total_score("COLIN"))
#print(len(names))
# print(get_letter_score('Z'))
# print(get_name_value("COLIN"))
# print(get_name_score("COLIN",938))
#print(names.index('"COLIN"'))
names = []
names = input_names('data/data_022.txt')
names.sort()
print(get_total_score(names))