Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).
%I #11 Aug 05 2022 07:42:42
%S 1,-1,-1,1,2,-1,-1,-1,-1,1,2,-1,-1,2,3,-1,-1,-1,-1,1,2,-1,-1,2,3,-1,
%T -1,-1,-1,2,3,-1,-1,3,1,2,-1,-1,2,3,-1,-1,-1,-1,2,3,-1,-1,3,4,-1,-1,
%U -1,-1,2,1,2,-1,3,2,3,-1,-1,-1,3,2,3,-1,4,3,4,-1,-1,-1,-1,2,3,-1,-1
%N Minimal number of distinct nonzero tetrahedral numbers needed to represent n, or -1 if no such representation is possible.
%H Robert Israel, <a href="/A102855/b102855.txt">Table of n, a(n) for n = 1..10000</a>
%p N:= 100; # for a(1)..a(N)
%p ft:= t -> t*(t+1)*(t+2)/6:
%p tets:= map(ft, [$1..floor((6*N)^(1/3))]:
%p f:= proc(n,tmax) option remember;
%p local res, s;
%p if member(n, tets) and n < tmax then return 1 fi;
%p min(seq(1 + procname(n-s,s), s=select(`<`,tets,min(n,tmax))));
%p end proc:
%p subs(infinity=-1,map(f, [$1..N],infinity)); # _Robert Israel_, Dec 29 2019
%t M = 100; (* number of terms *)
%t ft[t_] := t(t+1)(t+2)/6;
%t tets = ft /@ Range[1, Floor[(6M)^(1/3)]];
%t f[n_, tmax_] := f[n, tmax] = If[MemberQ[tets, n] && n < tmax, 1, Min[ Table[1 + f[n-s, s], {s, Select[tets, # < Min[n, tmax]&]}]]];
%t f[#, Infinity]& /@ Range[1, M] /. Infinity -> -1 (* _Jean-François Alcover_, Aug 05 2022, after _Robert Israel_ *)
%Y Cf. A104246, A102795-A102806, A102856-A102858.
%K sign
%O 1,5
%A _Jud McCranie_, Mar 01 2005