blob: febbe7c6d65f57fdad5988305e5cef1a41dd4774 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
def Triangle(n):
return (n*(n+1))/2
words = open(r"C:\Users\30720\Desktop\Programming\ProjectEuler\words.txt","r+")
wordsasstring = words.read()
Triangles = []
for x in range(1,10000):
Triangles.append(Triangle(x))
count,x,total = 0,0,0
x = wordsasstring.find("\"",x,len(wordsasstring)) + 1
print(x)
while x < len(wordsasstring):
num = 0
y = wordsasstring.find("\"",x,len(wordsasstring))
for i in range(x,y):
temp = wordsasstring[i]
if temp == "A": num += 1
elif temp == "B": num += 2
elif temp == "C": num += 3
elif temp == "D": num += 4
elif temp == "E": num += 5
elif temp == "F": num += 6
elif temp == "G": num += 7
elif temp == "H": num += 8
elif temp == "I": num += 9
elif temp == "J": num += 10
elif temp == "K": num += 11
elif temp == "L": num += 12
elif temp == "M": num += 13
elif temp == "N": num += 14
elif temp == "O": num += 15
elif temp == "P": num += 16
elif temp == "Q": num += 17
elif temp == "R": num += 18
elif temp == "S": num += 19
elif temp == "T": num += 20
elif temp == "U": num += 21
elif temp == "V": num += 22
elif temp == "W": num += 23
elif temp == "X": num += 24
elif temp == "Y": num += 25
elif temp == "Z": num += 26
x = y+3
if Triangles.count(num) > 0: total +=1
print(total)
|