Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import itertools
- def countArray(n,k,x):
- buildlis=[0]*(k+2)
- buildlis[0]=1
- buildlis[-1]=x
- t=1
- i=1
- while(t<k+1):
- buildlis[i]=t%(k+1)
- t+=1; i+=1
- #returns all possible combinations of numbers we need
- allperm=itertools.permutations(buildlis[1:-1], n-2)
- count=0;
- for perm in allperm:
- i=1; doub=False
- lis=list(perm)
- lis.insert(0,1)
- lis.insert(len(lis), x)
- #print(lis)
- while(i<n):
- if lis[i-1]==lis[i]:
- doub=True
- break #efficiecny
- i+=1
- if doub==False:
- print(lis) #let's see the ones that pass the criteria set
- count+=1
- return ("count array: ", count)
- print(countArray(4,4,2))
Add Comment
Please, Sign In to add comment