Skip to content

Add "partition number" p(n) #190

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

Open
inkydragon opened this issue May 10, 2025 · 0 comments
Open

Add "partition number" p(n) #190

inkydragon opened this issue May 10, 2025 · 0 comments

Comments

@inkydragon
Copy link
Member

inkydragon commented May 10, 2025

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:

@inkydragon inkydragon changed the title Add "partition numbers" Add "partition number" p(n) May 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant