September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
1
Task/Paraffins/00META.yaml
Normal file
1
Task/Paraffins/00META.yaml
Normal file
|
|
@ -0,0 +1 @@
|
|||
--- {}
|
||||
42
Task/Paraffins/Julia/paraffins.julia
Normal file
42
Task/Paraffins/Julia/paraffins.julia
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
const branches = 4
|
||||
const nmax = 500
|
||||
|
||||
const rooted = zeros(BigInt, nmax + 1)
|
||||
const unrooted = zeros(BigInt, nmax + 1)
|
||||
rooted[1] = rooted[2] = unrooted[1] = unrooted[2] = 1
|
||||
const c = zeros(BigInt, branches)
|
||||
|
||||
function tree(br, n, l, sum, cnt)
|
||||
for b in br+1:branches
|
||||
sum += n
|
||||
if (sum > nmax) || (l * 2 >= sum && b >= branches)
|
||||
return
|
||||
elseif b == br + 1
|
||||
c[br + 1] = rooted[n + 1] * cnt
|
||||
else
|
||||
c[br + 1] *= rooted[n + 1] + b - br - 1
|
||||
c[br + 1] = div(c[br + 1], b - br)
|
||||
end
|
||||
if l*2 < sum
|
||||
unrooted[sum + 1] += c[br + 1]
|
||||
end
|
||||
if b < branches
|
||||
rooted[sum + 1] += c[br + 1]
|
||||
end
|
||||
for m in n-1:-1:1
|
||||
tree(b, m, l, sum, c[br + 1])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
bicenter(n) = if iseven(n) unrooted[n + 1] += div(rooted[div(n, 2) + 1] * (rooted[div(n, 2) + 1] + 1), 2) end
|
||||
|
||||
function paraffins()
|
||||
for n in 1:nmax
|
||||
tree(0, n, n, 1, one(BigInt))
|
||||
bicenter(n)
|
||||
println("$n: $(unrooted[n + 1])")
|
||||
end
|
||||
end
|
||||
|
||||
paraffins()
|
||||
|
|
@ -1,14 +1,10 @@
|
|||
s[m_, p_, n_] :=
|
||||
CycleIndexPolynomial[SymmetricGroup[m],
|
||||
Table[ComposeSeries[p, x^i + O[x]^(n + 1)], {i, m}]];
|
||||
G000598[n_] := Nest[1 + x s[3, #, n] &, 1 + O[x], n];
|
||||
G000602[n_] :=
|
||||
Block[{x},
|
||||
x*CycleIndexPolynomial[SymmetricGroup[4],
|
||||
Table[ComposeSeries[#, x^i + O[x]^(n + 1)], {i, 4}]] -
|
||||
CycleIndexPolynomial[SymmetricGroup[2],
|
||||
Table[ComposeSeries[# - 1, x^i + O[x]^(n + 1)], {i, 2}]] +
|
||||
ComposeSeries[#, x^2 + O[x]^(n + 1)] &@
|
||||
Fold[Series[
|
||||
1 + x/6 (#1^3 + 3 #1 ComposeSeries[#1, x^2 + O[x]^#2] +
|
||||
2 ComposeSeries[#1, x^3 + O[x]^#2]), {x, 0, #2}] &,
|
||||
1 + O[x], Range[n + 1]]];
|
||||
x s[4, #, n] - s[2, # - 1, n] +
|
||||
ComposeSeries[#, x^2 + O[x]^(n + 1)] &[G000598[n]];
|
||||
A000602[n_] := SeriesCoefficient[G000602[n], n];
|
||||
A000602List[n_] := CoefficientList[G000602[n], x];
|
||||
Grid@Transpose@{Range[0, 200], A000602List@200}
|
||||
|
|
|
|||
46
Task/Paraffins/Phix/paraffins.phix
Normal file
46
Task/Paraffins/Phix/paraffins.phix
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
constant MAX_N = 32,
|
||||
BRANCH = 4
|
||||
|
||||
sequence {rooted,unrooted} @= repeat(0,MAX_N+2)
|
||||
|
||||
procedure tree(integer br, n, l=n, tot=1, atom cnt=1)
|
||||
atom c
|
||||
for b=br+1 to BRANCH do
|
||||
tot += n
|
||||
if tot>=MAX_N+1
|
||||
or (l*2>=tot and b>=BRANCH) then
|
||||
return
|
||||
end if
|
||||
if b==br+1 then
|
||||
c = rooted[n+1]*cnt
|
||||
else
|
||||
c *= (rooted[n+1]+(b-br-1))/(b-br)
|
||||
end if
|
||||
if l*2<tot then
|
||||
unrooted[tot+1] += c
|
||||
end if
|
||||
if b<BRANCH then
|
||||
rooted[tot+1] += c
|
||||
for m=1 to n-1 do
|
||||
tree(b,m,l,tot,c)
|
||||
end for
|
||||
end if
|
||||
end for
|
||||
end procedure
|
||||
|
||||
procedure bicenter(integer s)
|
||||
if mod(s,2)=0 then
|
||||
atom aux = rooted[s/2+1]
|
||||
unrooted[s+1] += aux*(aux+1)/2
|
||||
end if
|
||||
end procedure
|
||||
|
||||
rooted[1..2] = 1
|
||||
unrooted[1..2] = 1
|
||||
for n=1 to MAX_N do
|
||||
tree(0, n)
|
||||
bicenter(n)
|
||||
if n<10 or n=MAX_N then
|
||||
printf(1,"%d: %d\n",{n, unrooted[n+1]})
|
||||
end if
|
||||
end for
|
||||
32
Task/Paraffins/Python/paraffins-3.py
Normal file
32
Task/Paraffins/Python/paraffins-3.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from functools import lru_cache
|
||||
|
||||
def Z_S(n, f, k):
|
||||
"""
|
||||
The cycle index of the symmetric group has recurrence
|
||||
Z(S_n, f(x)) = 1/n \sum_{i=1}^n f(x^i) Z(S_{n-i}, f(x)).
|
||||
This function finds the coefficient of x^k in Z(S_n, f(x))
|
||||
"""
|
||||
# Special case to avoid division by zero
|
||||
if n == 0:
|
||||
return 1 if k == 0 else 0
|
||||
# Special case as a speed optimisation
|
||||
if n == 1:
|
||||
return f(k)
|
||||
return sum(
|
||||
sum(f(ij // i) * Z_S(n-i, f, k - ij) for ij in range(0, k+1, i))
|
||||
for i in range(1, n+1)
|
||||
) // n
|
||||
|
||||
@lru_cache(maxsize=None)
|
||||
def A000598(k): return 1 if k == 0 else Z_S(3, A000598, k-1)
|
||||
|
||||
@lru_cache(maxsize=None)
|
||||
def A000642(k): return Z_S(2, A000598, k)
|
||||
|
||||
def A000631(k): return Z_S(2, A000642, k)
|
||||
|
||||
def A000602(k): return A000642(k) + (A000642((k-1) // 2) if k % 2 == 1 else 0) - A000631(k-1)
|
||||
|
||||
for k in range(500): print(k, A000602(k))
|
||||
|
|
@ -1,27 +1,28 @@
|
|||
/*REXX program enumerates (without repetition) the # of paraffins with N atoms of carbon*/
|
||||
parse arg nodes . /*obtain optional argument from the CL.*/
|
||||
if nodes=='' | nodes=="," then nodes=100 /*Not specified? Then use the default.*/
|
||||
rooted. = 0; rooted.0=1; rooted.1=1 /*define the base rooted numbers.*/
|
||||
unrooted. = 0; unrooted.0=1; unrooted.1=1 /* " " " unrooted " */
|
||||
numeric digits max(9,nodes%2) /*this program may use gihugeic numbers*/
|
||||
w=length(nodes) /*W: used for aligning formatted nodes.*/
|
||||
say right(0,w) unrooted.0 /*show enumerations of 0 carbon atoms*/
|
||||
if nodes=='' | nodes=="," then nodes= 100 /*Not specified? Then use the default.*/
|
||||
rooted. = 0; rooted.0= 1; rooted.1= 1 /*define the base rooted numbers.*/
|
||||
unrooted. = 0; unrooted.0= 1; unrooted.1= 1 /* " " " unrooted " */
|
||||
numeric digits max(9, nodes % 2) /*this program may use gihugeic numbers*/
|
||||
w= length(nodes) /*W: used for aligning formatted nodes*/
|
||||
say right(0, w) unrooted.0 /*show enumerations of 0 carbon atoms*/
|
||||
/* [↓] process all nodes (up to NODES)*/
|
||||
do C=1 for nodes; h=C%2 /*C: is the number of carbon atoms. */
|
||||
do C=1 for nodes; h= C % 2 /*C: is the number of carbon atoms. */
|
||||
call tree 0, C, C, 1, 1 /* [↓] if # of carbon atoms is even···*/
|
||||
if C//2==0 then unrooted.C=unrooted.C + rooted.h * (rooted.h + 1) % 2
|
||||
say right(C,w) unrooted.C /*display an aligned formatted number. */
|
||||
if C//2==0 then unrooted.C= unrooted.C + rooted.h * (rooted.h + 1) % 2
|
||||
say right(C, w) unrooted.C /*display an aligned formatted number. */
|
||||
end /*C*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
tree: procedure expose rooted. unrooted. nodes #. /*this function is recursive.*/
|
||||
parse arg br,n,L,sum,cnt; nm=n-1; LL=L+L; brp=br+1
|
||||
do b=brp to 4; sum=sum+n; if sum>nodes then leave
|
||||
if b==4 then if LL>=sum then leave
|
||||
if b==brp then #.br=rooted.n * cnt
|
||||
else #.br=#.br * (rooted.n + b - brp) % (b - br)
|
||||
if LL<sum then unrooted.sum=unrooted.sum + #.br
|
||||
parse arg br,n,L,sum,cnt; nm= n - 1; LL= L + L; brp= br + 1
|
||||
do b=brp to 4; sum= sum + n; if sum>nodes then leave
|
||||
if b==4 then if LL>=sum then leave
|
||||
if b==brp then #.br= rooted.n * cnt
|
||||
else #.br= #.br * (rooted.n + b - brp) % (b - br)
|
||||
if LL<sum then unrooted.sum= unrooted.sum + #.br
|
||||
if b==4 then leave
|
||||
rooted.sum = rooted.sum + #.br
|
||||
do m=nm by -1 for nm; call tree b, m, L, sum, #.br; end /*m*/
|
||||
do m=nm by -1 for nm; call tree b, m, L, sum, #.br; end /*m*/
|
||||
end /*b*/ /* ↑↑↑↑↑↑↑↑↑ recursive invocation of TREE. */
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue