-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem_045_02.py
More file actions
79 lines (59 loc) · 1.69 KB
/
problem_045_02.py
File metadata and controls
79 lines (59 loc) · 1.69 KB
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
78
79
##Triangular, pentagonal, and hexagonal
##Problem 45
##Triangle, pentagonal, and hexagonal numbers are generated by the following formulae:
##
##Triangle Tn=n(n+1)/2 1, 3, 6, 10, 15, ...
##Pentagonal Pn=n(3n−1)/2 1, 5, 12, 22, 35, ...
##Hexagonal Hn=n(2n−1) 1, 6, 15, 28, 45, ...
##It can be verified that T285 = P165 = H143 = 40755.
##
##Find the next triangle number that is also pentagonal and hexagonal.
import numpy as np
import itertools
import math
import time
import eulertools as et
def isTriangle(number):
_tmp = 0
_conditionplus = (-1 + np.sqrt(1 + 8*number))/2
if int(_conditionplus) == _conditionplus:
_tmp = 1
return _tmp
def isPentagonal(number):
_tmp = 0
_conditionplus = (1+np.sqrt(1+24*number))/6
if int(_conditionplus) == _conditionplus:
_tmp = 1
return _tmp
def isHexagonal(number):
_tmp = 0
_conditionplus = (1+np.sqrt(1+8*number))/4
if int(_conditionplus) == _conditionplus:
_tmp = 1
return _tmp
def createTri(n):
return n * (n + 1) / 2
def createPent(n):
return n * (3 * n - 1) / 2
def createHex(n):
return n * (2 * n -1)
def euler45b():
upper_l = 100000
setA = set(createHex(i) for i in range(upper_l))
setB = set(createPent(i) for i in range(upper_l))
z = 2
flag = True
while z < upper_l and flag == True:
tmp_h = createTri(z)
if tmp_h in setA and tmp_h in setB:
print(tmp_h)
flag = False
def main():
start = time.time()
euler45b()
## print(evaluatelist(["SKY","REGIONAL"], triangles(1000)))
## print(valueword("ABOUT"))
## print(valueword("SKY"))
end = time.time()
print(end-start)
main()