#OK to post homework #George Spahn, 3/7/2021, Assignment 13 pnE:=proc(n) local p,j: option remember: p:=0: if n <= 0 then RETURN(0): fi: if n = 1 then RETURN(1): fi: for j from 1 do: if n-((3*j-1)*j)/2 < 0 then break: fi: p:=p+(-1)^(j+1)* pnE(n-((3*j-1)*j)/2): od: for j from 1 do: if n-((3*j-1)*j)/2 < 0 then break: fi: p:=p+(-1)^(j+1)* pnE(n-((3*j+1)*j)/2): od: end: pnSeqE:=proc(N) local n: [seq(pnE(n),n=1..N)]:end: #pnSeqE(1000) took maple .03 seconds #pnSeq(1000) took maple 49 seconds #Franklin(L) Inputs an integer partition with distinct parts # and outputs another such partition or FAIL Franklin:=proc(L) local m,s,i,L1: m:= L[-1]: s:=nops(L): for i from 1 to nops(L)-1 do if L[i] > L[i+1]+1 then s:=i: break: fi: od: if s= nops(L) and (m=s or m=s+1) then RETURN(FAIL): fi: if m>s then L1:=[op(L),s]: for i from 1 to s do L1[i]:=L[i]-1: od: fi: if m<=s then L1:=[seq(L[j],j=1..nops(L)-1)]: for i from 1 to m do L1[i]:=L[i]+1: od: fi: L1: end: #FranklinOldMaids(n) inputs a non-negative integer n, #and outputs the partitions for which Franklin(L) returns FAIL. FranklinOldMaids:=proc(n) local p,L: L:={}: for p in PnD(n,{0}) do if Franklin(p) = FAIL then L:=L union {p}: fi: od: L: end: #PnkD(n,k,DI): The set of integer partitions of n with largest part k, #where the difference of two consecutive parts is NOT in DI PnkD:=proc(n,k,DI) local k1,L,L1: option remember: if not (type(n,integer) and type(k,integer) and n>=1 and k>=1 )then RETURN({}): fi: if k>n then RETURN({}): fi: if k=n then RETURN({[n]}): fi: L:={}: for k1 from min(n-k,k) by -1 to 1 do if not(k-k1 in DI) then L1:=PnkD(n-k,k1,DI): L:=L union {seq([k, op(L1[j])],j=1..nops(L1))}: fi: od: L: end: #PnD(n,DI): The set of integer partitions of n #where the difference of two consecutive parts is NOT in DI PnD:=proc(n,DI) local k:option remember:[seq(op(PnkD(n,n-k+1,DI)),k=1..n)]:end: