MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / solution

Function solution

project_euler/problem_022/sol2.py:21–39  ·  view source on GitHub ↗

Returns the total of all the name scores in the file. >>> solution() 871198282

()

Source from the content-addressed store, hash-verified

19
20
21def solution():
22 """Returns the total of all the name scores in the file.
23
24 >>> solution()
25 871198282
26 """
27 total_sum = 0
28 temp_sum = 0
29 with open(os.path.dirname(__file__) + "/p022_names.txt") as file:
30 name = str(file.readlines()[0])
31 name = name.replace('"', "").split(",")
32
33 name.sort()
34 for i in range(len(name)):
35 for j in name[i]:
36 temp_sum += ord(j) - ord("A") + 1
37 total_sum += (i + 1) * temp_sum
38 temp_sum = 0
39 return total_sum
40
41
42if __name__ == "__main__":

Callers 1

sol2.pyFile · 0.70

Calls 2

splitMethod · 0.80
sortMethod · 0.80

Tested by

no test coverage detected