Initial commit
This commit is contained in:
27
problem-42.py
Normal file
27
problem-42.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import string
|
||||
import requests
|
||||
|
||||
MAX_NUM = 10000
|
||||
letter_values = dict(zip(string.ascii_uppercase, list(range(1, 27))))
|
||||
triangle_numbers = [0.5*n*(n+1) for n in range(MAX_NUM+1)]
|
||||
|
||||
def value(word):
|
||||
value = 0
|
||||
for letter in word:
|
||||
value += letter_values[letter]
|
||||
return value
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
data_url = 'https://projecteuler.net/project/resources/p042_words.txt'
|
||||
text = requests.get(data_url).text.replace('"', '')
|
||||
words = text.split(',')
|
||||
|
||||
results = []
|
||||
for word in words:
|
||||
if value(word) in triangle_numbers:
|
||||
results.append(word)
|
||||
print(results)
|
||||
print(len(results))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user