gen := proc(parents, maxgen, ocounts, lvl)
local thislbl, lbl, childlbl, counts, npar;
counts := ocounts;
counts[lvl] := counts[lvl]+1;
if nops(parents) < maxgen then
thislbl := op(-1, parents);
childlbl := 1;
for lbl from 1 to thislbl do
while ( childlbl in parents ) or ( childlbl = thislbl ) do
childlbl := childlbl+1;
od;
npar := [op(parents), childlbl];
if nops(counts) < lvl+1 then
counts := [op(counts), 0];
fi;
counts := gen(npar, maxgen, counts, lvl+1);
childlbl := childlbl+1;
od;
fi;
if lvl <= maxgen -4 then
print(counts);
fi;
RETURN(counts);
end:
maxgen := 8;
parents := [1, 2];
n := [1, 0];
gen(parents, maxgen, n, 2);
The following Maple10 code is from Alec Mihailovs: # (start)
f:=proc(n::integer[4], A::Array(datatype=integer[4]),
B::Array(datatype=integer[4]))::integer[4]; local c::integer[4],
i::integer[4], len::integer[4], m::integer[4]; c, len, m:=0, 3, 3;
while len>1 do if len=n then c:=c+1; m:=A[len]; B[m]:=0; len:=len-1;
B[A[len]]:=B[A[len]]+1 elif B[A[len]]<=A[len] then for i from m+1
do if B[i]=0 then break fi od; len:=len+1; A[len]:=i; B[i]:=1; m:=2
else m:=A[len]; B[m]:=0; len:=len-1; B[A[len]]:=B[A[len]]+1 fi od; c end:
cf:=Compiler:-Compile(f):
F:=proc(n::posint) local A, B;
if n<3 then 1 elif n=3 then 2 else
A:=Array([$1..3, 0$(n-3)], datatype=integer[4]);
B:=Array([1$3, 0$((n-2)*(n+1)/2)], datatype=integer[4]);
cf(n, A, B) fi end:
seq(F(n), n=1..12); # (end)
|