human
Count Knights that can attack a given pawn in an N * N board | Function to count the knights that are attacking the pawn in an M * M board.
Stores count of knights that are attacking the pawn.
Traverse the knights array.
Stores absolute difference of X co - ordinate of i - th knight and pawn.
Stores absolute difference of Y co - ordinate of i - th knight and pawn.
If X is 1 and Y is 2 or X is 2 and Y is 1.
Update cntKnights.
Driver code.
Stores total count of knights"
How can the above be solved in Python?
 ... Can you provide a code to count Knights that can attack a given pawn in an N * N board and the other steps required?
assistant
#Here is code to count Knights that can attack a given pawn in an N * N board and the other steps required.
 def cntKnightsAttackPawn ( knights , pawn , M ) :
	cntKnights = 0 ;
	for i in range ( M ) :
		X = abs ( knights [ i ] [ 0 ] - pawn [ 0 ] ) ;
		Y = abs ( knights [ i ] [ 1 ] - pawn [ 1 ] ) ;
		if ( ( X == 1 and Y == 2 ) or ( X == 2 and Y == 1 ) ) :
			cntKnights += 1 ;
	return cntKnights ;
if __name__ == ' _ _ main _ _ ' :
	knights = [ [ 0 , 4 ] , [ 4 , 5 ] , [ 1 , 4 ] , [ 3 , 1 ] ] ;
	pawn = [ 2 , 3 ] ;
	M = len ( knights ) ;
	print ( cntKnightsAttackPawn ( knights , pawn , M ) ) ;