Help:=proc(): print(`IsComp(v1,v2), BV(k) , NuT1(n,v) , NuT(n) `): end: #IsComp(v1,v2): true iff v2 can be on top of v1 in a legal triangle IsComp:=proc(v1,v2) local i: if nops(v1)-nops(v2)<>1 then RETURN(FAIL): fi: for i from 2 to nops(v1)-1 do if v1[i]=1 and v2[i-1]=0 and v2[i]=0 then RETURN(false): fi: od: if v1[1]=1 and v2[1]=0 then RETURN(false): fi: if v1[nops(v1)]=1 and v2[nops(v2)]=0 then RETURN(false): fi: true: end: #NuT1: inputs a pos. integer n and a 0-1 vector v #of size k (say), finds the number of legal triangles #with exactly n 1's, with v he bottom row NuT1:=proc(n,v) local k,N,S,nu,s,t: option remember: k:=nops(v): if k=1 and v[1]=1 then if n=1 then RETURN(1): else RETURN(0): fi: fi: if k=1 and v[1]=0 then if n=0 then RETURN(1): else RETURN(0): fi: fi: N:=convert(v,`+`): S:=BV(k-1): t:=0: for s in S do if IsComp(v,s) then t:=t+NuT1(n-N,s): fi: od: t: end: #BV(k): all 0-1 vectors of size k BV:=proc(k) local S,s: if k=0 then RETURN({[]}): fi: S:=BV(k-1): {seq([op(s),0], s in S), seq([op(s),1], s in S)}: end: #the number of directed animals with n dots NuT:=proc(n) local k,t,s,S: t:=0: for k from 1 to n do S:=BV(k) minus {[0\$k]}: t:=t+add(NuT1(n,s), s in S): od: t: end: