I would like to find every combination of elements in a list, by switching the order of the elements, while keeping their count and the length of the list.
For example, for the list:
[1,2,1,3]
I would like to obtain the following:
[1,1,2,3]
[1,1,3,2]
[1,2,1,3]
[1,2,3,1]
[1,3,1,2]
[1,3,2,1]
[2,1,1,3]
[2,1,3,1]
[2,3,1,1]
[3,1,1,2]
[3,1,2,1]
[3,2,1,1]
Be aware that same elements, such as the two 1 in the original list, are not seen as separate ones, so the two possibilities [1a,1b,2,3]
and [1b,1a,2,3]
must be counted as one