From 1161f9a034de06a63538e3a9a0b7717098c744d9 Mon Sep 17 00:00:00 2001 From: Joshua Drake Date: Fri, 7 Apr 2023 08:13:49 -0500 Subject: Initial Commit --- Problem42.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Problem42.py (limited to 'Problem42.py') diff --git a/Problem42.py b/Problem42.py new file mode 100644 index 0000000..febbe7c --- /dev/null +++ b/Problem42.py @@ -0,0 +1,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) + \ No newline at end of file -- cgit v1.2.3