Skip to content

Commit d933e95

Browse files
committed
doc: add examples for nthperm!(a, k)
1 parent 911e70f commit d933e95

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/permutations.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,36 @@ end
263263
nthperm!(a, k)
264264
265265
In-place version of [`nthperm`](@ref); the array `a` is overwritten.
266+
267+
# Examples
268+
```jldoctest
269+
julia> a = [1, 2, 3];
270+
271+
julia> collect(permutations(a))
272+
6-element Vector{Vector{Int64}}:
273+
[1, 2, 3]
274+
[1, 3, 2]
275+
[2, 1, 3]
276+
[2, 3, 1]
277+
[3, 1, 2]
278+
[3, 2, 1]
279+
280+
julia> nthperm!(a, 3); a
281+
3-element Vector{Int64}:
282+
2
283+
1
284+
3
285+
286+
julia> nthperm!(a, 4); a
287+
3-element Vector{Int64}:
288+
1
289+
3
290+
2
291+
292+
julia> nthperm!(a, 0)
293+
ERROR: ArgumentError: permutation k must satisfy 0 < k ≤ 6, got 0
294+
[...]
295+
```
266296
"""
267297
function nthperm!(a::AbstractVector, k::Integer)
268298
n = length(a)

0 commit comments

Comments
 (0)