for i1 in range(1,4):
for i2 in range(1,4):
if i2 ! = i1:
for i3 in range(1,4):
if i3 ! = i1 and i3 ! = i2:
print(i1,i2,i3)
중복순열 예시
arr = [1,2,3,4,5,6]
path = ['']*3
def abc(level):
if level ==3:
for i in range(level):
print(path[i], end = '')
print()
return
for i in range(6):
path[level] = arr[i]
abc(level+1)
path[level]=0
abc(0)
순열 예시
path=['']*3
dice=[1,2,3,4,5,6]
used=[0]*6
def abc(level):
if level==3:
for i in range(level):
print(path[i],end=' ')
print()
return
for i in range(6):
if used[i] == 1: continue
path[level]=dice[i]
used[i] =1
abc(level+1)
used[i] = 0
path[level]=0
abc(0)