Skip to content

Commit 8e29d31

Browse files
committed
doc: add doc and examples for ncpartitions(n::Int)
1 parent 2ad84aa commit 8e29d31

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

src/partitions.jl

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,46 @@ function integer_partitions(n::Integer)
474474
end
475475

476476

477-
478-
#Noncrossing partitions
477+
# Noncrossing partitions
479478

480479
const _cmp = cmp
481480

482-
#Produces noncrossing partitions of length n
481+
"""
482+
ncpartitions(n::Int)
483+
484+
Generates all noncrossing partitions of a set of `n` elements,
485+
returning them as a `Vector` of partition representations.
486+
487+
The number of noncrossing partitions of an `n`-element set
488+
is given by the n-th Catalan number `Cn`:
489+
`length(ncpartitions(n)) == catalannum(n)`.
490+
491+
See also: [`catalannum`](@ref)
492+
493+
# Examples
494+
```jldoctest
495+
julia> ncpartitions(1)
496+
1-element Vector{Vector{Vector{Int64}}}:
497+
[[1]]
498+
499+
julia> ncpartitions(3)
500+
5-element Vector{Vector{Vector{Int64}}}:
501+
[[1], [2], [3]]
502+
[[1], [2, 3]]
503+
[[1, 2], [3]]
504+
[[1, 3], [2]]
505+
[[1, 2, 3]]
506+
507+
julia> catalannum(3)
508+
5
509+
510+
julia> length(ncpartitions(6)) == catalannum(6)
511+
true
512+
```
513+
514+
# References
515+
- [Noncrossing partition - Wikipedia](https://en.wikipedia.org/wiki/Noncrossing_partition)
516+
"""
483517
function ncpartitions(n::Int)
484518
partitions = Vector{Vector{Int}}[]
485519
_ncpart!(1,n,n,Vector{Int}[], partitions)

0 commit comments

Comments
 (0)