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

Function is_right

project_euler/problem_091/sol1.py:17–37  ·  view source on GitHub ↗

Check if the triangle described by P(x1,y1), Q(x2,y2) and O(0,0) is right-angled. Note: this doesn't check if P and Q are equal, but that's handled by the use of itertools.combinations in the solution function. >>> is_right(0, 1, 2, 0) True >>> is_right(1, 0, 2, 2) Fals

(x1: int, y1: int, x2: int, y2: int)

Source from the content-addressed store, hash-verified

15
16
17def is_right(x1: int, y1: int, x2: int, y2: int) -> bool:
18 """
19 Check if the triangle described by P(x1,y1), Q(x2,y2) and O(0,0) is right-angled.
20 Note: this doesn't check if P and Q are equal, but that's handled by the use of
21 itertools.combinations in the solution function.
22
23 >>> is_right(0, 1, 2, 0)
24 True
25 >>> is_right(1, 0, 2, 2)
26 False
27 """
28 if x1 == y1 == 0 or x2 == y2 == 0:
29 return False
30 a_square = x1 * x1 + y1 * y1
31 b_square = x2 * x2 + y2 * y2
32 c_square = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)
33 return (
34 a_square + b_square == c_square
35 or a_square + c_square == b_square
36 or b_square + c_square == a_square
37 )
38
39
40def solution(limit: int = 50) -> int:

Callers 1

solutionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected