MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / solution

Function solution

project_euler/problem_091/sol1.py:40–54  ·  view source on GitHub ↗

Return the number of right triangles OPQ that can be formed by two points P, Q which have both x- and y- coordinates between 0 and limit inclusive. >>> solution(2) 14 >>> solution(10) 448

(limit: int = 50)

Source from the content-addressed store, hash-verified

38
39
40def solution(limit: int = 50) -> int:
41 """
42 Return the number of right triangles OPQ that can be formed by two points P, Q
43 which have both x- and y- coordinates between 0 and limit inclusive.
44
45 >>> solution(2)
46 14
47 >>> solution(10)
48 448
49 """
50 return sum(
51 1
52 for pt1, pt2 in combinations(product(range(limit + 1), repeat=2), 2)
53 if is_right(*pt1, *pt2)
54 )
55
56
57if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls 2

is_rightFunction · 0.85
combinationsFunction · 0.50

Tested by

no test coverage detected