%I
%S 3,5,5,0,0,3,0,0,0,0,1,2,0,0,1,2,1,0,0,0,2,0,0,0,4,0,2,0,0,1,2,0,0,0,
%T 1,2,0,1,0,0,2,0,0,0,3,0,0,0,0,0,2,2,0,0,0,4,1,0,2,0,2,0,0,0,1,0,0,0,
%U 0,0,3,2,0,0,0,1,0,0,4,0,2,0,3,0,2,4
%N Greedy residue sequence of tetrahedral numbers 4, 10, 20, 35, ...
%C Suppose that s = (s(1), s(2), ... ) is a sequence of real numbers such that for every real number u, at most finitely many s(i) are < u, and suppose that x > min(s). We shall apply the greedy algorithm to x, using terms of s. Specifically, let i(1) be an index i such that s(i) = max{s(j) < x}, and put d(1) = x  s(i(1)). If d(1) < s(i) for all i, put r = x  s(i(1)). Otherwise, let i(2) be an index i such that s(i) = max{s(j) < x  s(i(1))}, and put d(2) = x  s(i(1))  s(i(2)). If d(2) < s(i) for all i, put r = x  s(i(1))  s(i(2)). Otherwise, let i(3) be an index i such that s(i) = max{s(j) < x  s(i(1))  s(i(2))}, and put d(3) = x  s(i(1))  s(i(2))  s(i(3)). Continue until reaching k such that d(k) < s(i) for every i, and put r = x  s(i(1))  ...  s(i(k)). Call r the sgreedy residue of x, and call s(i(1)) + ... + s(i(k)) the sgreedy sum for x. If r = 0, call x sgreedy summable. If s(1) = min(s) < s(2), then taking x = s(i) successively for i = 2, 3,... gives a residue r(i) for each i; call (r(i)) the greedy residue sequence for s. When s is understood from context, the prefix "s" is omitted. For A242288, s = (1,4,10,20,...); s(n) = n(n + 1)(n+2)/6.
%H Clark Kimberling, <a href="/A242288/b242288.txt">Table of n, a(n) for n = 2..2000</a>
%e n ... n(n+1)(n+2)/6 ... a(n)
%e 1 .. 1 ............... (undefined)
%e 2 ... 4 ............... 3 = 4  1
%e 3 ... 10 .............. 5 = 10  4  1
%e 4 ... 20 .............. 15 = 20  10  4  1
%e 5 ... 35 .............. 0 = 35  20  10  4 1 1
%e 6 ... 56 .............. 0 = 56  35  20  1
%e 7 ... 84 .............. 3 = 84  56  20  4  1
%e 8 ... 120 ............. 0 = 120  84  35  1
%e 9 ... 165 ............. 0 = 165  120  35  10
%e 10 .. 220 ............. 0 = 220  165  35  20
%e 11 .. 286 ............. 0 = 286  220  56  10
%t z = 200; s = Table[n (n + 1)(n + 2)/6, {n, 1, z}]; t = Table[{s[[n]], #, Total[#] == s[[n]]} &[DeleteCases[Differences[FoldList[If[#1  #2 >= 0, #1  #2, #1] &, s[[n]], Reverse[Select[s, # < s[[n]] &]]]], 0]], {n, z}]
%t r[n_] := s[[n]]  Total[t[[n]][[2]]];
%t tr = Table[r[n], {n, 2, z}] (* A242288 *)
%t c = Table[Length[t[[n]][[2]]], {n, 2, z}] (* A242289 *)
%t f = 1 + Flatten[Position[tr, 0]] (* A242290*)
%t f (f + 1)(f + 2)/6 (* A242291 *) (* _Peter J. C. Moses_, May 06 2014 *)
%Y Cf. A242289, A242290, A242291, A241833, A242284, A000292.
%K nonn,easy
%O 2,1
%A _Clark Kimberling_, May 10 2014
