Given a list of binary numbers (0s and 1s), determine the number of possible arrangements of distinct binary sequences using given 0s and 1s

Viewed 2089

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="")

Click here to see my output

3 Answers
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)
import math
n=input().split()
a=math.factorial(len(n))//(math.factorial(n.count("1"))*math.factorial(n.count("0")));
print(a,end="")
def fact(n):
  if(n==0):
    return 1
  else:
    return n*fact(n-1)
  
myList = list(map(int,input().split()))
a = myList.count(0)
b = myList.count(1)
c = len(myList)
print(int(fact(c)/(fact(a)*fact(b))),end="")
Related