def factorial(n):
if n <= 0:
return 1
return n * factorial(n-1)
print(factorial(3));
ex) {1,2,3} 의 순열 : {1,2,3}, {1,3,2}, {2,1,3}, {2,3,1}, {3,1,2}, {3,2,1}
def permutation(arr, start):
if len(arr) - 1 == start:
print('start : {}, permutation : {}'.format(start, arr))
return
for i in range(start, len(arr)):
arr[start], arr[i] = arr[i], arr[start]
print('start:{}, index:{}, arr:{}'.format(start, i, arr))
permutation(arr, start + 1)
#arr[start], arr[i] = arr[i], arr[start]
arr = [1,2,3]
permutation(arr, 0)