38 lines
972 B
Python
38 lines
972 B
Python
|
def euler_135():
|
||
|
n = 10**7
|
||
|
threshold = 10**6
|
||
|
lookup = {i: 0 for i in range(1, threshold)}
|
||
|
firstpositivestart = 1
|
||
|
for x in range(1, n):
|
||
|
firstpositive = False
|
||
|
for dxy in range(firstpositivestart, x // 2 + 1):
|
||
|
z = x - 2 * dxy
|
||
|
if z <= 0:
|
||
|
break
|
||
|
y = x - dxy
|
||
|
xyz = x*x - y*y - z*z
|
||
|
if xyz <= 0:
|
||
|
continue
|
||
|
|
||
|
# Start when xyz is already greater than 0.
|
||
|
if not firstpositive:
|
||
|
firstpositivestart = dxy
|
||
|
firstpositive = True
|
||
|
|
||
|
# If xyz is greater than threshold there are no more solutions.
|
||
|
if xyz >= threshold:
|
||
|
break
|
||
|
lookup[xyz] += 1
|
||
|
|
||
|
r = 0
|
||
|
for _, v in lookup.items():
|
||
|
if v == 10:
|
||
|
r += 1
|
||
|
return r
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
solution = euler_135()
|
||
|
print("e135.py: " + str(solution))
|
||
|
assert solution == 4989
|