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

Function solution

project_euler/problem_009/sol3.py:20–40  ·  view source on GitHub ↗

Returns the product of a,b,c which are Pythagorean Triplet that satisfies the following: 1. a**2 + b**2 = c**2 2. a + b + c = 1000 >>> solution() 31875000

()

Source from the content-addressed store, hash-verified

18
19
20def solution() -> int:
21 """
22 Returns the product of a,b,c which are Pythagorean Triplet that satisfies
23 the following:
24 1. a**2 + b**2 = c**2
25 2. a + b + c = 1000
26
27 >>> solution()
28 31875000
29 """
30
31 return next(
32 iter(
33 [
34 a * b * (1000 - a - b)
35 for a in range(1, 999)
36 for b in range(a, 999)
37 if (a * a + b * b == (1000 - a - b) ** 2)
38 ]
39 )
40 )
41
42
43if __name__ == "__main__":

Callers 1

sol3.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected