Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
33
Task/Partition-function-P/Julia/partition-function-p.julia
Normal file
33
Task/Partition-function-P/Julia/partition-function-p.julia
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
using Memoize
|
||||
|
||||
function partDiffDiff(n::Int)::Int
|
||||
isodd(n) ? (n+1)÷2 : n+1
|
||||
end
|
||||
|
||||
@memoize function partDiff(n::Int)::Int
|
||||
n<2 ? 1 : partDiff(n-1)+partDiffDiff(n-1)
|
||||
end
|
||||
|
||||
@memoize function partitionsP(n::Int)
|
||||
T=BigInt
|
||||
if n<2
|
||||
one(T)
|
||||
else
|
||||
psum = zero(T)
|
||||
for i ∈ 1:n
|
||||
pd = partDiff(i)
|
||||
if pd>n
|
||||
break
|
||||
end
|
||||
if ((i-1)%4)<2
|
||||
psum += partitionsP(n-pd)
|
||||
else
|
||||
psum -= partitionsP(n-pd)
|
||||
end
|
||||
end
|
||||
psum
|
||||
end
|
||||
end
|
||||
|
||||
n=6666
|
||||
@time println("p($n) = ", partitionsP(n))
|
||||
Loading…
Add table
Add a link
Reference in a new issue