The following code is finding permutation, but the count
variable is not updating. Can anyone please point out the mistake as to why the change in count
is not reflected.
def swap_arr_elems(arr, src_idx, dest_idx):
tmp = arr[src_idx]
arr[src_idx] = arr[dest_idx]
arr[dest_idx] = tmp
return
def permuate(arr, left, right, output, count):
if left == right:
output.append(list(arr))
count += 1
#count.append('1')
return
for i in range(left, right, 1):
swap_arr_elems(arr, left, i)
permuate(arr, left + 1, right, output, count)
swap_arr_elems(arr, left, i)
if __name__ == '__main__':
count = 0
#count = []
test_input = ['a', 'b', 'c']
test_output = []
permuate(test_input, 0, len(test_input), test_output, count)
print("count : " + str(count))
for item in test_output:
print(item)
EDIT 1:
output of the above code is:
count : 0
['a', 'b', 'c']
['a', 'c', 'b']
['b', 'a', 'c']
['b', 'c', 'a']
['c', 'b', 'a']
['c', 'a', 'b']