human
Write me a code to count of even and odd set bit with array element after XOR with K and the other steps required given the following:
Count of even and odd set bit with array element after XOR with K | Function to store EVEN and odd variable.
Store the count of even and odd set bit.
Count the set bit using in built function.
Count of set - bit of K.
If y is odd then , count of even and odd set bit will be interchanged.
Else it will remain same as the original array.
Driver 's Code.
Function call to count even and odd"
Solution in Python:
assistant
#Here is code to count of even and odd set bit with array element after XOR with K and the other steps required.
 def countEvenOdd ( arr , n , K ) :
	even = 0 ; odd = 0 ;
	for i in range ( n ) :
		x = bin ( arr [ i ] ) . count ( '1' ) ;
		if ( x % 2 == 0 ) :
			even += 1 ;
		else :
			odd += 1 ;
	y = bin ( K ) . count ( '1' ) ;
	if ( y & 1 ) :
		print ( " Even ▁ = " , odd , " , ▁ Odd ▁ = " , even ) ;
	else :
		print ( " Even ▁ = " , even , " , ▁ Odd ▁ = " , odd ) ;
if __name__ == " _ _ main _ _ " :
	arr = [ 4 , 2 , 15 , 9 , 8 , 8 ] ;
	K = 3 ;
	n = len ( arr ) ;
	countEvenOdd ( arr , n , K ) ;