Skip to content

doc: add more examples and test for partitions #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
May 7, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
doc: update doc and examples for integer_partitions(n)
  • Loading branch information
inkydragon committed May 3, 2025
commit 5fd8008477b1c5a5773314d7ced1f8b12e9c8837
34 changes: 33 additions & 1 deletion src/partitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,43 @@ end
"""
integer_partitions(n)

List the partitions of the integer `n`.
Generates all partitions of the integer `n` as a list of integer arrays,
where each partition represents a way to write `n` as a sum of positive integers.

See also: [`partitions(n::Integer)`](@ref)

!!! note
The order of the resulting array is consistent with that produced by the computational
discrete algebra software GAP.

# Examples
```jldoctest
julia> integer_partitions(2)
2-element Vector{Vector{Int64}}:
[1, 1]
[2]

julia> integer_partitions(3)
3-element Vector{Vector{Int64}}:
[1, 1, 1]
[2, 1]
[3]

julia> collect(partitions(3))
3-element Vector{Vector{Int64}}:
[3]
[2, 1]
[1, 1, 1]

julia> integer_partitions(-1)
ERROR: DomainError with -1:
n must be nonnegative
Stacktrace:
[...]
```

# References
- [Integer partition - Wikipedia](https://en.wikipedia.org/wiki/Integer_partition)
"""
function integer_partitions(n::Integer)
if n < 0
Expand Down