%I #28 Mar 03 2024 09:30:10
%S 0,1,2,3,2,3,4,5,4,5,4,5,4,5,4,5,4,5,6,7,6,7,6,5,6,5,6,5,6,5,6,5,6,7,
%T 8,7,8,7,6,7,6,7,6,7,6,7,6,7,6,7,6,7,6,7,6,7,6,7,6,7,6,7,6,7,6,7,8,9,
%U 8,9,8,9,8,9,8,9,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7
%N Height of n-th term in Recamán's sequence A005132.
%C The height of a term in A005132 = number of addition steps - number of subtraction steps to produce it.
%C Partial sums of A160357. - _Allan C. Wechsler_, Sep 08 2019
%H Alois P. Heinz, <a href="/A064289/b064289.txt">Table of n, a(n) for n = 0..100000</a>
%H Nick Hobson, <a href="/A064289/a064289.py.txt">Python program for this sequence</a>
%H N. J. A. Sloane, <a href="/A005132/a005132.txt">FORTRAN program for A005132, A057167, A064227, A064228</a>
%H <a href="/index/Rea#Recaman">Index entries for sequences related to Recamán's sequence</a>
%e A005132 begins 1, 3, 6, 2, 7, 13, 20, 12, ... and these terms have heights 1, 2, 3, 2, 3, 4, 5, 4, ...
%p g:= proc(n) is(n=0) end:
%p b:= proc(n) option remember; local t;
%p if n=0 then 0 else t:= b(n-1)-n; if t<=0 or g(t)
%p then t:= b(n-1)+n fi; g(t):= true; t fi
%p end:
%p a:= proc(n) option remember; `if`(n=0, 0,
%p a(n-1)+signum(b(n)-b(n-1)))
%p end:
%p seq(a(n), n=0..120); # _Alois P. Heinz_, Sep 08 2019
%t g[n_] := n == 0;
%t b[n_] := b[n] = Module[{t}, If[n == 0, 0, t = b[n - 1] - n; If[t <= 0 || g[t], t = b[n - 1] + n]; g[t] = True; t]];
%t a[n_] := a[n] = If[n == 0, 0, a[n - 1] + Sign[b[n] - b[n - 1]]];
%t a /@ Range[0, 100] (* _Jean-François Alcover_, Apr 11 2020, after _Alois P. Heinz_ *)
%Y Cf. A005132, A064288, A064290, A064292, A064293, A064294, A160357.
%K nonn,easy
%O 0,3
%A _N. J. A. Sloane_, Sep 25 2001
%E a(0)=0 prepended by _Allan C. Wechsler_, Sep 08 2019