Skip to content

Commit 5fd8008

Browse files
committed
doc: update doc and examples for integer_partitions(n)
1 parent dd3d707 commit 5fd8008

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

src/partitions.jl

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,11 +446,43 @@ end
446446
"""
447447
integer_partitions(n)
448448
449-
List the partitions of the integer `n`.
449+
Generates all partitions of the integer `n` as a list of integer arrays,
450+
where each partition represents a way to write `n` as a sum of positive integers.
451+
452+
See also: [`partitions(n::Integer)`](@ref)
450453
451454
!!! note
452455
The order of the resulting array is consistent with that produced by the computational
453456
discrete algebra software GAP.
457+
458+
# Examples
459+
```jldoctest
460+
julia> integer_partitions(2)
461+
2-element Vector{Vector{Int64}}:
462+
[1, 1]
463+
[2]
464+
465+
julia> integer_partitions(3)
466+
3-element Vector{Vector{Int64}}:
467+
[1, 1, 1]
468+
[2, 1]
469+
[3]
470+
471+
julia> collect(partitions(3))
472+
3-element Vector{Vector{Int64}}:
473+
[3]
474+
[2, 1]
475+
[1, 1, 1]
476+
477+
julia> integer_partitions(-1)
478+
ERROR: DomainError with -1:
479+
n must be nonnegative
480+
Stacktrace:
481+
[...]
482+
```
483+
484+
# References
485+
- [Integer partition - Wikipedia](https://en.wikipedia.org/wiki/Integer_partition)
454486
"""
455487
function integer_partitions(n::Integer)
456488
if n < 0

0 commit comments

Comments
 (0)