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

Function solution_fast

project_euler/problem_009/sol1.py:41–59  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

39
40
41def solution_fast() -> int:
42 """
43 Returns the product of a,b,c which are Pythagorean Triplet that satisfies
44 the following:
45 1. a < b < c
46 2. a**2 + b**2 = c**2
47 3. a + b + c = 1000
48
49 >>> solution_fast()
50 31875000
51 """
52
53 for a in range(300):
54 for b in range(400):
55 c = 1000 - a - b
56 if a < b < c and (a**2) + (b**2) == (c**2):
57 return a * b * c
58
59 return -1
60
61
62def benchmark() -> None:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected