MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / solution

Function solution

project_euler/problem_086/sol1.py:72–100  ·  view source on GitHub ↗

Return the least value of M such that there are more than one million cuboids of side lengths 1 <= a,b,c <= M such that the shortest distance between two opposite vertices of the cuboid is integral. >>> solution(100) 24 >>> solution(1000) 72 >>> solution(2000) 10

(limit: int = 1000000)

Source from the content-addressed store, hash-verified

70
71
72def solution(limit: int = 1000000) -> int:
73 """
74 Return the least value of M such that there are more than one million cuboids
75 of side lengths 1 <= a,b,c <= M such that the shortest distance between two
76 opposite vertices of the cuboid is integral.
77 >>> solution(100)
78 24
79 >>> solution(1000)
80 72
81 >>> solution(2000)
82 100
83 >>> solution(20000)
84 288
85 """
86 num_cuboids: int = 0
87 max_cuboid_size: int = 0
88 sum_shortest_sides: int
89
90 while num_cuboids <= limit:
91 max_cuboid_size += 1
92 for sum_shortest_sides in range(2, 2 * max_cuboid_size + 1):
93 if sqrt(sum_shortest_sides**2 + max_cuboid_size**2).is_integer():
94 num_cuboids += (
95 min(max_cuboid_size, sum_shortest_sides // 2)
96 - max(1, sum_shortest_sides - max_cuboid_size)
97 + 1
98 )
99
100 return max_cuboid_size
101
102
103if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected