-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrying.py
178 lines (133 loc) · 3.51 KB
/
trying.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# I'm going to solve a series of excercises from the website called 'projecteuler.net'
import math
# ---------------------------------------------------------------------------------
"""
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.
"""
def exercise3():
c = int(input("type the amount: "))
for i in triangle_loop(c):
#print(i)
for j in pentagonal_loop(c):
#print(j)
for k in hexagonal_loop(c):
#print(k)
if i == j and i == k:
print(k)
# listnum = []
"""
for n in range(2, count + 1):
T = n * (n + 1) / 2
for m in range(2, count):
P = m * (3 * m - 1) / 2
for l in range(2, count):
H = l * (2 * l - 1)
if T == P and T == H:
# listnum.append(T)
yield T
counter = 1
n = 1
m = 1
l = 1
while True:
T = n * (n + 1) / 2
P = m * (3 * m - 1) / 2
H = l * (2 * l - 1)
if T == P and T == H:
yield T
counter = counter + 1
if counter == 2:
break
n = n + 1
m = m + 1
l = l + 1
"""
# print("the numbers that are triangle, pentagonal and hexagonal")
# print(listnum, sep=",")
def triangle_loop(count):
for n in range(1, count+1):
T = n * (n + 1) / 2
yield T
def pentagonal_loop(count):
for m in range(1, count+1):
P = m * (3 * m - 1) / 2
yield P
def hexagonal_loop(count):
for l in range(1, count+1):
H = l * (2 * l - 1)
yield H
# exercise number 4
# --------------------------------------------------------------------------------------
def f(n, m):
i = 0
n_i = 0
while True:
L = sumDigit(i)
if L == n:
n_i = n_i + 1
if n_i == m:
return i
i = i + 1
def sumDigit(value):
s = 0
nstr = str(value)
for j in range(len(nstr)):
s = s + int(nstr[j])
return s
def s(k):
lst = []
for n in range(1, k + 1):
v = f(math.pow(n, 3), math.pow(n, 4))
lst.append(v)
absum = math.fsum(lst)
print(absum)
def stwo(k):
absum = 0
for n in range(1, k + 1):
v = f(math.pow(n, 3), math.pow(n, 4))
absum = absum + v
print(absum % 1000000007)
# -----------------------------------------------------------------
def binarySeries():
pass
# RUN
exercise3()
# exercise4
# print(f(10, 100))
print("-" * 30)
# s(10)
# stwo(3)
"""
problem
"""
import math
def posibilities(to_number):
for a in range(1, to_number):
for b in range(1, to_number):
for c in range(1, to_number):
if c == math.sqrt(b**2+a**2):
p = a+b+c
if p == to_number:
yield a, b, c
def count_p(ps):
c = 0
for k in posibilities(ps):
print(k)
c+=1
return c/2
def require(to):
lt = []
n = 1
while n <=to:
c = count_p(n)
print(c)
lt.append(c)
n +=1
return lt
print(max(require(1000)))