Natija:
(1, 2)
(1, 3)
(1, 4)
(2, 1)
(2, 3)
(2, 4)
(3, 1)
(3, 2)
(3, 4)
(4, 1)
(4, 2)
(4, 3)
2)Alohida funksiya yordamida dastur tuzamiz:
def guruhlash(ketma_ketlik , uzunlik , x = object()):
if uzunlik<=0:
kombinatsiya = [x]
else:
kombinatsiya= []
for i, a in enumerate(ketma_ketlik , 1):
w = ketma_ketlik[i:]
q = guruhlash(w , uzunlik-1)
kombinatsiya.extend(a if komb is x else [a , komb]
for komb in q)
return kombinatsiya
m = []
lk = int(input("ketma ketlik sonini kiriting: "))
for h in range(1,lk+1):
m.append(h)
lm = int(input('nechtadan guruhlansin: '))
xm = guruhlash(m , lm)
for i in list(xm):
print(i)
Natija quyidagicha:
ketma ketlik sonini kiriting: 4
nechtadan guruhlansin: 2
[1, 2]
[1, 3]
[1, 4]
[2, 3]
[2, 4]
[3, 4]
Do'stlaringiz bilan baham: |