euler/python/e086.py

36 lines
804 B
Python
Raw Normal View History

2021-04-10 05:44:28 +02:00
2021-04-21 18:14:57 +02:00
def shortest_path_squared(l, b, h):
s1 = l ** 2 + (h + b) ** 2
s2 = h ** 2 + (b + l) ** 2
s3 = b ** 2 + (h + l) ** 2
s = min(s1, s2, s3)
return s
2021-04-10 05:44:28 +02:00
def euler_086():
2021-04-21 18:14:57 +02:00
square_max = (10 ** 6) ** 2
squares = set([n * n for n in range(10**6)])
count = 0
m = 0
while True:
m += 1
cuboids = ((m, a, b)
for a in range(1, m + 1)
for b in range(1, a + 1))
for c in cuboids:
s = shortest_path_squared(*c)
if s in squares:
count += 1
if s > square_max:
raise Exception()
if count > 10 ** 6:
return m
2021-04-10 05:44:28 +02:00
if __name__ == "__main__":
solution = euler_086()
print("e086.py: " + str(solution))
2021-04-21 18:14:57 +02:00
assert(solution == 1818)