Initial commit

This commit is contained in:
Kevin Keogh
2018-07-02 15:45:49 -04:00
parent 60b3954a3b
commit fd817f8811
28 changed files with 809 additions and 0 deletions

27
problem-42.py Normal file
View 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))