I've been trying to code 3 different recursive function(Backtracking). The first one should show all permutations(orders doesn't matters) and there's a specif size. The second one should show all cyclic permutations. The third one should show all permutations(orders matters) and there's a specif size.
I was able to do the first one by myself:
def Arranjo(list, repeat):
if repeat <= 0:
return [[]]
solution = []
for i in range(0, len(list)):
remainingList = list[:i] + list[i + 1 :]
for j in Arranjo(remainingList, repeat - 1):
solution.append([list[i]] + j)
return solution
# 0 to 100
list = [x for x in range(1, 101)]
print(Arranjo(list, 3))
I've been facing some issues in the other two exercises. I've already spent hours trying to do the second exercise, but I don't have any idea about how to do it. That's what I was able to do:
def PermutacaoCircular(list):
if len(list) == 0:
return
elif len(list) == 1:
return list
else:
solution = []
sub_solution = []
for i in range(len(list)):
// code here
return solution
list = [1, 2, 3]
print(PermutacaoCircular(list))
The third one, I don't even know how to start.