-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path42.py
77 lines (69 loc) · 1.53 KB
/
42.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#-*-coding:utf8;-*-
#qpy:3
#qpy:console
import time
import os
#decorator that gets time of program
def dect(func):
def timef():
t0 = time.time()
func()
t1 = time.time()
print(t1 - t0)
return timef
def is_triangular(number):
x = 1
while number > 0:
number -= x
x += 1
return number == 0
@dect
def main():
alph_ord = {"A":1,
"B":2,
"C":3,
"D":4,
"E":5,
"F":6,
"G":7,
"H":8,
"I":9,
"J":10,
"K":11,
"L":12,
"M":13,
"N":14,
"O":15,
"P":16,
"Q":17,
"R":18,
"S":19,
"T":20,
"U":21,
"V":22,
"W":23,
"X":24,
"Y":25,
"Z":26,
"\"":0,
"\'":0,
}
path = "/sdcard/qpython/scripts3/Project_Euler/"
os.chdir(path)
with open(path + "p042_words.txt","r") as F:
words = list(F)[0].split(",")
words.sort()
count = 0
for word in words:
Sum = 0
for char in word:
Sum += alph_ord[char]
"""
if char == '"':
continue
Sum += ord(char) - 64
"""
if is_triangular(Sum):
count += 1
print(count)
main()