Skip to content

Add "partition number" p(n) #190

Open
@inkydragon

Description

@inkydragon

partition_num(n::Int) == length(integer_partitions(n::Int)) == length(partitions(n::Int))

Clean and export npartitions

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions