human
Find all even length binary sequences with same sum of first and second half bits | Iterative | Function to convert the number into binary and store the number into an array.
Function to check if the sum of the digits till the mid of the array and the sum of the digits from mid till n is the same , if they are same then print that binary.
Calculating the sum from 0 till mid and store in sum1.
Calculating the sum from mid till n and store in sum2.
If sum1 is same as sum2 print the binary.
Function to prsequence.
Creating the array.
'' Looping over powers of 2 .
Converting the number into binary first.
Checking if the sum of the first half of the array is same as the sum of the next half.
Driver Code"
How can the above be solved in Python?
 ... Write me a code to find all even length binary sequences with same sum of first and second half bits and the other steps required?
assistant
#Here is code to find all even length binary sequences with same sum of first and second half bits and the other steps required.
 def convertToBinary ( num , a , n ) :
	pointer = n - 1
	while ( num > 0 ) :
		a [ pointer ] = num % 2
		num = num // 2
		pointer -= 1
def checkforsum ( a , n ) :
	sum1 = 0
	sum2 = 0
	mid = n // 2
	for i in range ( mid ) :
		sum1 = sum1 + a [ i ]
	for j in range ( mid , n ) :
		sum2 = sum2 + a [ j ]
	if ( sum1 == sum2 ) :
		for i in range ( n ) :
			print ( a [ i ] , end = " " )
		print ( )
def print_seq ( m ) :
	n = ( 2 * m )
	a = [ 0 for i in range ( n ) ]
	for i in range ( pow ( 2 , n ) ) :
		convertToBinary ( i , a , n )
		checkforsum ( a , n )
m = 2
print_seq ( m )