Count pairs of coordinates connected by a line with slope in the range [ | Function to find the number of pairs of points such that the line passing through them has a slope in the range [ - k , k ] ; Store the result ; Traverse through all the combination of points ; If pair satisfies the given condition ; Increment ans by 1 ; Print the result ; Driver Code ; Function Call
def findPairs ( x , y , K ) : NEW_LINE INDENT n = len ( x ) NEW_LINE ans = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT if ( K * abs ( x [ i ] - x [ j ] ) >= abs ( y [ i ] - y [ j ] ) ) : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT X = [ 2 , 1 , 0 ] NEW_LINE Y = [ 1 , 2 , 0 ] NEW_LINE K = 1 NEW_LINE findPairs ( X , Y , K ) NEW_LINE DEDENT