Skip to content

Commit 040f76c

Browse files
authored
Create permutations_of_an_array.py
1 parent 2d8f22a commit 040f76c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class permutation:
2+
def __init__(self):
3+
self.__n=int(input('array size : '))
4+
self.__arr=[]
5+
for i in range (0,self.__n):
6+
a=input(f'input for idx {i}: ')
7+
self.__arr.append(int(a))
8+
9+
def __get_permutations(self,lst,res,arr,n):
10+
if(len(lst)==n):
11+
res.append(lst[:])
12+
return
13+
for i in range (0,len(arr)):
14+
lst.append(arr[i])
15+
self.__get_permutations(lst,res,arr[0:i]+arr[i+1:],n)
16+
lst.pop()
17+
18+
def compute_permutations(self):
19+
lst=[]
20+
res=[]
21+
self.__get_permutations(lst,res,self.__arr,self.__n)
22+
print('the permutations are\n')
23+
print(res)
24+
25+
a=permutation()
26+
a.compute_permutations()
27+

0 commit comments

Comments
 (0)