Next time inspect target file better
This commit is contained in:
24
22/main.py
24
22/main.py
@@ -3,19 +3,35 @@ import math
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
def charScore(c):
|
||||||
|
assert len(c) == 1
|
||||||
|
|
||||||
|
return ord(c.lower()) - 96
|
||||||
|
|
||||||
|
def strScore(s):
|
||||||
|
res = 0
|
||||||
|
for c in s:
|
||||||
|
res = res + charScore(c)
|
||||||
|
|
||||||
|
return res
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print("Hello, this is Patrick")
|
print("Hello, this is Patrick")
|
||||||
|
|
||||||
f = open("names.txt", 'r')
|
f = open("names.txt", 'r')
|
||||||
names = []
|
names = f.readline()
|
||||||
for name in f:
|
f.close()
|
||||||
names.append(name)
|
|
||||||
|
|
||||||
|
names = names.strip('\"').split("\",\"")
|
||||||
names.sort()
|
names.sort()
|
||||||
|
|
||||||
print(names)
|
scores = []
|
||||||
|
for i in range(len(names)):
|
||||||
|
n = names[i]
|
||||||
|
score = strScore(n) * (i + 1)
|
||||||
|
scores.append(score)
|
||||||
|
|
||||||
|
print(sum(scores))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
Reference in New Issue
Block a user