From 8c80fdb3c1d7b9aa89752e4ae03b33f39e21a4cb Mon Sep 17 00:00:00 2001 From: Felix Martin Date: Wed, 21 Apr 2021 12:14:57 -0400 Subject: [PATCH] Solve problem 86 --- python/e086.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/python/e086.py b/python/e086.py index 6bbf48b..5547d5c 100644 --- a/python/e086.py +++ b/python/e086.py @@ -1,9 +1,35 @@ +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 + + def euler_086(): - return 0 + 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 if __name__ == "__main__": solution = euler_086() print("e086.py: " + str(solution)) - assert(solution == 0) + assert(solution == 1818) +