human
Make all array elements equal by replacing triplets with their Bitwise XOR | Function to find triplets such that replacing them with their XOR make all array elements equal.
If N is even.
Calculate xor of array elements.
Traverse the array.
Update xor.
If xor is not equal to 0.
Selecting the triplets such that elements of the pairs ( arr [ 0 ] , arr [ 1 ] ) , ( arr [ 2 ] , arr [ 3 ] ) . . . can be made equal.
Selecting the triplets such that all array elements can be made equal to arr [ N - 1 ].
Selecting the triplets such that elements of the pairs ( arr [ 0 ] , arr [ 1 ] ) , ( arr [ 2 ] , arr [ 3 ] ) . . . can be made equal.
Selecting the triplets such that all array elements can be made equal to arr [ N - 1 ].
Driver code.
Given array.
Size of array.
Function call"
Solution in Python:
 ... Write me a code to make all array elements equal by replacing triplets with their Bitwise XOR and the other steps required?
assistant
#Here is code to make all array elements equal by replacing triplets with their Bitwise XOR and the other steps required.
 def checkXOR ( arr , N ) :
	if ( N % 2 == 0 ) :
		xro = 0 ;
		for i in range ( N ) :
			xro ^= arr [ i ] ;
		if ( xro != 0 ) :
			print ( - 1 ) ;
			return ;
		for i in range ( 0 , N - 3 , 2 ) :
			print ( i , " ▁ " , ( i + 1 ) , " ▁ " , ( i + 2 ) , end = " ▁ " ) ;
		for i in range ( 0 , N - 3 , 2 ) :
			print ( i , " ▁ " , ( i + 1 ) , " ▁ " , ( N - 1 ) , end = " ▁ " ) ;
	else :
		for i in range ( 0 , N - 2 , 2 ) :
			print ( i , " ▁ " , ( i + 1 ) , " ▁ " , ( i + 2 ) ) ;
		for i in range ( 0 , N - 2 , 2 ) :
			print ( i , " ▁ " , ( i + 1 ) , " ▁ " , ( N - 1 ) ) ;
if __name__ == ' _ _ main _ _ ' :
	arr = [ 4 , 2 , 1 , 7 , 2 ] ;
	N = len ( arr ) ;
	checkXOR ( arr , N ) ;