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.
JavaScript
x
12
12
1
import math
2
c=input().split()
3
a=0
4
b=0
5
for i in c:
6
if int(i)==0:
7
b+=1
8
if int(i)==1:
9
a+=1
10
answer=int(math.factorial(len(c))/(math.factorial(a)*math.factorial(b)))
11
print(answer,end="")
12
Advertisement
Answer
JavaScript
1
13
13
1
import math
2
c=input()
3
c=list(c)
4
a=0
5
b=0
6
for i in c:
7
if int(i)==0:
8
a+=1
9
if int(i)==1:
10
b+=1
11
answer=int(math.factorial(len(c))/(math.factorial(a)*math.factorial(b)))
12
print(answer)
13