human
1 to n bit numbers with no consecutive 1 s in binary representation | Python3 program to print all numbers upto n bits with no consecutive set bits ..
Let us first compute 2 raised to power n ..
loop 1 to n to check all the numbers.
A number i doesn ' t ▁ contain ▁ ▁ consecutive ▁ set ▁ bits ▁ if ▁ ▁ bitwise ▁ and ▁ of ▁ i ▁ and ▁ left ▁ ▁ shifted ▁ i ▁ do ' t contain a common set bit ..
Driver code"
How can the above be solved in Python?
 ... What is a code to 1 to n bit numbers with no consecutive 1 s in binary representation and the other steps required?
assistant
#Here is code to 1 to n bit numbers with no consecutive 1 s in binary representation and the other steps required.
 def printNonConsecutive ( n ) :
	p = ( 1 << n )
	for i in range ( 1 , p ) :
		if ( ( i & ( i << 1 ) ) == 0 ) :
			print ( i , end = " ▁ " )
n = 3
printNonConsecutive ( n )