+ 1

can anybody answer this? I couldn't get the logic

Print pattern like this Example: Input: 1 Output: 0 Input: 2 Output: 0 0 0 1 1 0 1 1

11th Jun 2021, 2:09 PM
Gayathri
Gayathri - avatar
16 Answers
+ 9
n - input Yeah so checking the pattern, you've to print n^2 permutations with 0/1 as numbers in it Loop for n^2 times and print different arrangments of size "n"
11th Jun 2021, 2:26 PM
Nikhil
Nikhil - avatar
+ 4
Those are binary number with n digits. For ex: n=1 Output: 0 or 1 n=2: a= 0 ,b=0 = 0 0, 1. =1 a= 1, 0. =2 1, 1 =3 n= 3, take a ,b, c 0 0 0 = 0 0 0 1 = 1 0 1 0 = 2 0 1 1 = 3 1 0 0 = 4 1 0 1 = 5 1 1 0 = 6 1 1 1 = 7 how many number are forming by n digits .. It's equally n*n binary numbers from 0 to n^2-1 (n squire -1) for n=4, you get 0 to 15 (4*4-1=15) 0 0 0 0 (0) to .... .... 1 1 1 1 (15) can say it as different permutations with values 0,1 filled in n places. Gayathri hope it helps.....
11th Jun 2021, 2:33 PM
Jayakrishna 🇮🇳
+ 2
I think how many permutations can be made by in range(0, n). What is output if input is 3? where do you found this?
11th Jun 2021, 2:17 PM
Jayakrishna 🇮🇳
+ 2
for Input: 3 Output: 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1
11th Jun 2021, 2:19 PM
Gayathri
Gayathri - avatar
+ 2
You could have to implement binary number generator function by your own with spaces adding between.. I think it is not difficult.... edit : Gayathri see this , you can find an idea how to implement it.. https://www.rapidtables.com/convert/number/decimal-to-binary.html
11th Jun 2021, 3:25 PM
Jayakrishna 🇮🇳
+ 2
Solve the problem by building a function that return the successor of the inputing result; add +1. Let B’ becomes the binary successor of the binary number B. Let bn, b(n-1), ..., b0 be the digits in B from left to right. Thus: Decimal repr of B: B|10|= (bn * 2**n) + ... + (b1 * 2**1) + (b0 * 2**0) Binary repr: B = bn ... b1 b0 bi = 0 or bi = 1. c0 <= i <= n and n is a non negativ integer in B|10|. b0 is the rightmost digit in B, and bn the leftmost digit. B contains (n + 1) digits. To get B:s successor B’: Start with the leftmost digit bi in B, where i=0 (pseudo code): i = 0 while i <= n: # n from B|10| if bi == 0: bi = 1 break # Finished! else: bi = 0 if i == n: # The leftmost digit. b(n+1) = 1 # Add a new digit! i += 1 The successor B’ will contain between (n+1) to (n+2) digits. Here’s a example of what I meant above: https://code.sololearn.com/c3mwKO8kCz38/?ref=app Now try to solve your problem. If you stuck, we help you.
12th Jun 2021, 7:39 PM
Per Bratthammar
Per Bratthammar - avatar
+ 1
https://www.sololearn.com/post/1132307/?ref=app this is what I'm asking about👆🙂
11th Jun 2021, 2:26 PM
Gayathri
Gayathri - avatar
+ 1
i could understand the concept but how to print those binary numbers without using the builtin function
11th Jun 2021, 3:12 PM
Gayathri
Gayathri - avatar
+ 1
tnq u so much Jayakrishna🇮🇳 🤗i got it
11th Jun 2021, 4:03 PM
Gayathri
Gayathri - avatar
0
You're welcome Gayathri ..
11th Jun 2021, 4:04 PM
Jayakrishna 🇮🇳
0
Python language is logic take that product cross produc. ..diagognal product and print it after that....
12th Jun 2021, 4:21 PM
native buckeye
0
0000 0010 0110 0101 1010 0011 1100 1110 0111
12th Jun 2021, 11:19 PM
Asim Farheen ⭐⭐🤺👿👿
Asim  Farheen ⭐⭐🤺👿👿 - avatar
0
For input:3 Output: 0000 0011 01010 1111
13th Jun 2021, 5:39 AM
App Creator
App Creator - avatar
0
print("Hi Binary Printing Algo Here") inp_num=int(input("Enter The Number : ")) for i in range(0,2**inp_num): print(bin(i)[2:]) Maybe this should help u ..
13th Jun 2021, 6:32 AM
Lokesh
Lokesh - avatar
0
Sorry
13th Jun 2021, 12:58 PM
Derek Lo
Derek Lo - avatar
0
Gayathri Here's a possible solution: for i in range(k:=(2**int(input()))): print(bin(i)[2:].zfill(len(bin(k))-3)) # Hope this helps
13th Jun 2021, 3:28 PM
Calvin Thomas
Calvin Thomas - avatar