nthperm!

..  nthperm!(v, k)

In-place version of :func:`nthperm`.

Examples

The nthperm!(v, k) function in Julia generates the k-th permutation of the elements in the array v in-place.

julia> arr = [1, 2, 3];
julia> nthperm!(arr, 2)
3-element Array{Int64,1}:
 1
 3
 2

This example demonstrates generating the 2nd permutation of the array [1, 2, 3] in-place. The resulting permutation is [1, 3, 2].

Common mistake example:

julia> arr = [1, 2, 3];
julia> nthperm!(arr, 6)
ERROR: BoundsError: attempt to access 3-element Array{Int64,1} at index [6]

In this example, the provided index 6 is out of bounds for the array. It is crucial to ensure that the index is within the valid range for the given array length to avoid such errors. Always verify that k is a valid position in the array before using nthperm!.

See Also

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: