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)
| 38 | |
| 39 | |
| 40 | def 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 | |
| 57 | if __name__ == "__main__": |
no test coverage detected