human
Write me a code to count paths with distance equal to Manhattan distance and the other steps required given the following:
Count paths with distance equal to Manhattan distance | Function to return the value of nCk.
Since C ( n , k ) = C ( n , n - k ).
Calculate value of [ n * ( n - 1 ) * -- - * ( n - k + 1 ) ] / [ k * ( k - 1 ) * -- - * 1 ].
Function to return the number of paths.
Difference between the ' x ' coordinates of the given points.
Difference between the ' y ' coordinates of the given points.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to count paths with distance equal to Manhattan distance and the other steps required.
 def binomialCoeff ( n , k ) :
	res = 1
	if ( k > n - k ) :
		k = n - k
	for i in range ( k ) :
		res *= ( n - i )
		res //= ( i + 1 )
	return res
def countPaths ( x1 , y1 , x2 , y2 ) :
	m = abs ( x1 - x2 )
	n = abs ( y1 - y2 )
	return ( binomialCoeff ( m + n , n ) )
x1 , y1 , x2 , y2 = 2 , 3 , 4 , 5
print ( countPaths ( x1 , y1 , x2 , y2 ) )