human
Binary string with given frequencies of sums of consecutive pairs of characters | A Function that generates and returns the binary string.
P : Frequency of consecutive characters with sum 0 Q : Frequency of consecutive characters with sum 1 R : Frequency of consecutive characters with sum 2.
If no consecutive character adds up to 1.
Not possible if both P and Q are non - zero.
If P is not equal to 0.
Append 0 P + 1 times.
Append 1 R + 1 times.
Append "01" to satisfy Q.
Append "0" P times.
Append "1" R times.
Driver Code"
Solution in Python:
 ... Write me a code to binary string with given frequencies of sums of consecutive pairs of characters and the other steps required?
assistant
#Here is code to binary string with given frequencies of sums of consecutive pairs of characters and the other steps required.
 def build_binary_str ( p , q , r ) :
	ans = " "
	if ( q == 0 ) :
		if ( p != 0 and r != 0 ) :
			return " - 1"
		else :
			if ( p ) :
				temp = " "
				for i in range ( p + 1 ) :
					temp += '0'
				ans = temp
			else :
				temp = " "
				for i in range ( r + 1 ) :
					temp += '1'
				ans = temp
	else :
		for i in range ( 1 , q + 2 ) :
			if ( i % 2 == 0 ) :
				ans += '0'
			else :
				ans += '1'
		temp = " "
		for i in range ( p ) :
			temp += '0'
		st = " "
		st += ans [ 0 ]
		st += temp
		for i in range ( 1 , len ( ans ) ) :
			st += ans [ i ]
		ans = st
		temp = " "
		for i in range ( r ) :
			temp += '1'
		ans = temp + ans
	return ans
if __name__ == ' _ _ main _ _ ' :
	p = 1
	q = 2
	r = 2
	print ( build_binary_str ( p , q , r ) )