Skip to content

Commit

Permalink
permutation, combination
Browse files Browse the repository at this point in the history
  • Loading branch information
uniqueimaginate committed Apr 6, 2021
1 parent fa09932 commit afde1f3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Coding Test/combination.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
result = []

def combination(arr, size, ele):
if len(ele) == size:
result.append(ele[:])
return

for i in range(len(arr)):
ele.append(arr[i])
combination(arr[i+1:], size, ele)
ele.pop()


combination(range(9), 1, []) # 1개 조합
combination(range(9), 2, []) # 2개 조합
combination(range(9), 3, []) # 3개 조합
combination(range(9), 4, []) # 4개 조합
combination(range(9), 5, []) # 5개 조합

print(result)
22 changes: 22 additions & 0 deletions Coding Test/permutation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
result = []
def permutation(arr, size, ele):

if len(ele) == size:
result.append(ele[:])
return

for i in range(len(arr)):
ele.append(arr[i])
temp = arr[:]
temp.remove(arr[i])
permutation(temp, size, ele)
ele.pop()


permutation(range(9), 1, []) # 1개 순열
permutation(range(9), 2, []) # 2개 순열
permutation(range(9), 3, []) # 3개 순열
permutation(range(9), 4, []) # 4개 순열
permutation(range(9), 5, []) # 5개 순열

print(result)

0 comments on commit afde1f3

Please sign in to comment.