Initial commit
This commit is contained in:
24
problem-22.py
Normal file
24
problem-22.py
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
import requests
|
||||
import string
|
||||
|
||||
if __name__ == '__main__':
|
||||
url = 'https://projecteuler.net/project/resources/p022_names.txt'
|
||||
text = requests.get(url).text.replace('"', '')
|
||||
names = sorted(text.split(','))
|
||||
letter_values = dict(zip(string.ascii_uppercase, list(range(1, 27))))
|
||||
|
||||
total = 0
|
||||
for idx, name in enumerate(names):
|
||||
name_total = 0
|
||||
for letter in name:
|
||||
name_total += letter_values[letter]
|
||||
if name == 'COLIN':
|
||||
print(name, idx+1, name_total, (idx+1) * name_total)
|
||||
total += (idx+1) * name_total
|
||||
print(total)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user