Permutation: Swap blocks...

A command to swap the contents of two index ranges in the selected Permutation.

Settings

From index, To index
the two starting positions from where elements are to be swapped. The blocks may overlap.
Block size
determines the number of pairs to swap.

Behaviour

If the Block size equals one, only the elements at the From index and To index position are swapped. If blocksize is greater than one, the two elements at From index+1 and To index+1 will be swapped too. This goes on until the last two elements in each block have been swapped.

Examples

1. Swap two blocks: with From index = 1, To index = 4, and Block size = 2, the permutation (1,2,3,4,5) is turned into (4,5,3,1,2).

2. Swap two elements: with From index = 1, To index = 4, and Block size = 1, the permutation (1,2,3,4,5) is turned into (4,2,3,1,5).

3. Swap two overlapping blocks: with From index = 1, To index = 3, and Block size = 3, the permutation (1,2,3,4,5) is turned into (3,4,5,2,1).


© djmw, January 5, 2011