-
Notifications
You must be signed in to change notification settings - Fork 60
Open
Description
partition_num(n::Int) == length(integer_partitions(n::Int)) == length(partitions(n::Int))
Clean and export npartitions
Combinatorics.jl/src/partitions.jl
Lines 105 to 124 in edb9c2c
| let _npartitions = Dict{Int,Int}() | |
| global npartitions | |
| function npartitions(n::Int) | |
| if n < 0 | |
| 0 | |
| elseif n < 2 | |
| 1 | |
| elseif (np = get(_npartitions, n, 0)) > 0 | |
| np | |
| else | |
| np = 0 | |
| sgn = 1 | |
| for k = 1:n | |
| np += sgn * (npartitions(n - (k*(3k-1)) >> 1) + npartitions(n - (k*(3k+1)) >> 1)) | |
| sgn = -sgn | |
| end | |
| _npartitions[n] = np | |
| end | |
| end | |
| end |
ref:
Metadata
Metadata
Assignees
Labels
No labels