조합
def combi(arr, r):
for i in range(len(arr)):
if r == 1:
yield [arr[i]]
else:
for next in combi(arr[i + 1:], r - 1):
yield [arr[i]] + next
print(list(combi([1, 2, 3, 4], 2)))
중복조합
def combi2(arr, r):
for i in range(len(arr)):
if r == 1:
yield [arr[i]]
else:
for next in combi2(arr[i:], r - 1):
yield [arr[i]] + next
print(list(combi2([1, 2, 3, 4], 2)))
중복순열
def perm2(arr, r):
for i in range(len(arr)):
if r == 1:
yield [arr[i]]
else:
for next in perm2(arr, r - 1):
yield [arr[i]] + next
print(list(perm2([1, 2, 3, 4], 2)))