Given a list of binary numbers (0s and 1s), determine the number of possible arrangements of distinct binary sequences using given 0s and 1s.
Input Format:
A single line of input containing 0s and 1s
Output Format:
Print an integer value indicating the number of possible arrangements using given 0s and 1s
Example:
Input:
0 1 0 1
Output:
6
Explanation:
For the given input, the possible distinct binary sequences that can be formed are 0011, 0101, 0110, 1001, 1010, 1100.
Hence the output is 6. I have tried this but getting error.
import math
c=input().split()
a=0
b=0
for i in c:
if int(i)==0:
b+=1
if int(i)==1:
a+=1
answer=int(math.factorial(len(c))/(math.factorial(a)*math.factorial(b)))
print(answer,end="")
Advertisement
Answer
import math
c=input()
c=list(c)
a=0
b=0
for i in c:
if int(i)==0:
a+=1
if int(i)==1:
b+=1
answer=int(math.factorial(len(c))/(math.factorial(a)*math.factorial(b)))
print(answer)