# Talk:Permutations by swapping

## Does "Python: recursive" fit this task?

The "Python: recursive" solution doesn't seem to use swaps, which I thought was the whole point of this task. We already have a Permutations task for generating permutations in general. --Spoon! 17:58, 26 July 2012 (UTC)

- It also doesn't generate the output requested (it's missing the signs). Not that I think it should, though; right now, too much of this task smells of “let's write the task to force my code to be a solution”. OTOH, if I was to take the version that
*does*formally satisfy the task as described, it wouldn't be usable in the other task linked. Oh dear, oh dear! I think this draft task needs cleaning up, and the cleaning needs to be done by someone other than the original author with an eye to maximizing coherence and the ability to implement reasonably in many languages. –Donal Fellows 19:27, 26 July 2012 (UTC)

Hi Spoon, Donal; A quote from the Wikipedia article:

*"Each permutation in the sequence that it generates differs from the previous permutation by swapping two adjacent elements of the sequence."*

Do I need to make clear that the program does not have to generate using swaps - only that the above holds true? --Paddy3118 20:11, 26 July 2012 (UTC)

- Yep the task description did need tidying up, which I have started.
- The task was written so that it could be a precursor to a method for calculating a determinant which needs a sequence of permutations and matching sign. (The sign is generated in the recursive solution Donal, and the outputs of both Python solutions match).
- Hopefully with these modifications the task should be in a fit state to be attempted in other languages. --Paddy3118 20:31, 26 July 2012 (UTC)

- So the order of the output doesn't matter, as long as it is true that adjacent results differ by a swap of adjacent elements? How would one verify this easily? Perhaps a function to verify that the results satisfy this should be a part of the task, because it is insufficient to simply show that all the permutations are generated. --Spoon! 00:07, 3 August 2012 (UTC)
- Well:
- If the items doesn't change. (Sort them and compare).
- And if exactly two items are not in the same position as before.
- Then the two consecutive permutations are OK.

- --Paddy3118 07:35, 3 August 2012 (UTC)
- This is confusing. If the task is to use the Steinhaus–Johnson–Trotter algorithm then the permutations must appear in a specific order. If the task is to find the parity of a permutation, then we do not need the Steinhaus–Johnson–Trotter algorithm. So... what's the task? --Rdm 07:58, 3 August 2012 (UTC)

- Well:

- So the order of the output doesn't matter, as long as it is true that adjacent results differ by a swap of adjacent elements? How would one verify this easily? Perhaps a function to verify that the results satisfy this should be a part of the task, because it is insufficient to simply show that all the permutations are generated. --Spoon! 00:07, 3 August 2012 (UTC)

## bear in mind?

Currently the task says "Such data are of use in generating the determinant of a square matrix and any functions created should bear this in mind."

But what does this mean? Functions do not have minds... (Or, being slightly less flip: this feels like it could easily become a modularity violation if it were refined into something testable.) --Rdm 13:22, 30 July 2012 (UTC)

- It can be used directly in the formula there for calculating a determinant using the sign and the permutations. (But, from the talk page, you don't have to use any particular algorithm) --Paddy3118 15:56, 30 July 2012 (UTC)