

A025480


a(2n) = n, a(2n+1) = a(n).


73



0, 0, 1, 0, 2, 1, 3, 0, 4, 2, 5, 1, 6, 3, 7, 0, 8, 4, 9, 2, 10, 5, 11, 1, 12, 6, 13, 3, 14, 7, 15, 0, 16, 8, 17, 4, 18, 9, 19, 2, 20, 10, 21, 5, 22, 11, 23, 1, 24, 12, 25, 6, 26, 13, 27, 3, 28, 14, 29, 7, 30, 15, 31, 0, 32, 16, 33, 8, 34, 17, 35, 4, 36, 18, 37, 9, 38, 19, 39, 2, 40, 20, 41, 10
(list;
graph;
refs;
listen;
history;
text;
internal format)



OFFSET

0,5


COMMENTS

These are the Grundy values or nimvalues for heaps of n beans in the game where you're allowed to take up to half of the beans in a heap.  R. K. Guy, Mar 30 2006. See Levine 2004/2006 for more about this.  N. J. A. Sloane, Aug 14 2016
When n > 0 is written as (2k+1)*2^j then k = a(n1) and j = A007814(n), so: when n is written as (2k+1)*2^j1 then k = a(n) and j = A007814(n+1), when n > 1 is written as (2k+1)*2^j+1 then k = a(n2) and j = A007814(n1).  Henry Bottomley, Mar 02 2000 [sequence id corrected by Peter Munn, Jun 22 2022]
According to the comment from Deuard Worthen (see Example section), this may be regarded as a triangle where row r=1,2,3,... has length 2^(r1) and values T(r,2k1)=T(r1,k), T(r,2k)=2^(r1)+k1; i.e., previous row gives 1st, 3rd, 5th, ... term and 2nd, 4th, ... terms are numbers 2^(r1),...,2^r1 (i.e., those following the last one from the previous row).  M. F. Hasler, May 03 2008
Let StB be a SternBrocot tree hanging between (pseudo)fractions Left and Right, then StB(1) = mediant(Left,Right) and for n>1: StB(n) = if a(n1)<>0 and a(n)<>0 then mediant(StB(a(n1)),StB(a(n))) else if a(n)=0 then mediant(StB(a(n1)),Right) else mediant(Left,StB(a(n1))), where mediant(q1,q2) = ((numerator(q1)+numerator(q2)) / (denominator(q1)+denominator(q2))).  Reinhard Zumkeller, Dec 22 2008
This sequence is the unique fixed point of the function (a(0), a(1), a(2), ...) > (0, a(0), 1, a(1), 2, a(2), ...) which interleaves the nonnegative integers between the elements of a sequence.  Cale Gibbard (cgibbard(AT)gmail.com), Nov 18 2009
Also the number of remaining survivors in a Josephus problem after the person originally first in line has been eliminated (see A225381).  Marcus Hedbring, May 18 2013
One of a family of fractal sequences, S_k; defined as follows for k >= 2: a(k*n) = n, a(k*n+r) = a((k1)*n + (r1)), r = 1..(k1). S_2 is A025480; S_3 gives: a(3*n) = n, a(3*n + 1) = a(2*n), a(3*n + 2) = a(2*n + 1), which is A263390.
The subsequence of all nonzero terms is A131987. (End)
This sequence can be otherwise defined in two alternative (but related) ways, with a(0)=0, as follows: (i) If a(n) is a novel term, then a(n+1) = a(a(n)); if a(n) has been seen before, most recently at a(m), then a(n+1) = nm (as in A181391). (ii) As above for novel a(n), then if a(n) has been seen before, a(n+1) = smallest k < a(n) which is not already a term.  David James Sycamore, Jul 13 2021
From a binary perspective, the sequence can be seen as even,odd pairs where the odd value is the previous even value, dropping the rightmost bits up to and including the lowest zero bit, aka rightshifted past the lowest clear bit. E.g., (5)101 > 1, (17)10001 > (4)100, (29)11101 > (7)111, (39)100111 > (2)10.  Joe Nellis, Oct 09 2022


REFERENCES

L. Levine, Fractal sequences and restricted Nim, Ars Combin. 80 (2006), 113127.


LINKS



FORMULA

2^A007814(n+1)*(2*a(n)+1) = n+1. (See functions hd, tl and cons in [Paul Tarau 2009].)  Paul Tarau (paul.tarau(AT)gmail.com), Mar 21 2010
G.f.: 1/(1x) + Sum_{k>=0} x^(2^k1)/(12*x^2^(k+1)+x^2^(k+2)).  Ralf Stephan, May 19 2013
Recursion: a(0) = 0; a(n + 1) = a(a(n)) if a(n) is a first occurrence of a term, else a(n + 1) = n  a(n1).  David James Sycamore, Apr 29 2020
Sum_{k=1..n} a(k) = n^2/6 + O(n).  Amiram Eldar, Aug 07 2023


EXAMPLE

From Deuard Worthen (deuard(AT)raytheon.com), Jan 27 2006: (Start)
The sequence can be constructed as a triangle as:
0
0 1
0 2 1 3
0 4 2 5 1 6 3 7
0 8 4 9 2 10 5 11 1 12 6 13 3 14 7 15
...
At each stage we interleave the next 2^m numbers in the previous row. (End)


MAPLE

option remember ;
if type(n, 'even') then
n/2 ;
else
procname((n1)/2) ;
end if;
end proc:


MATHEMATICA

a[n_] := a[n] = If[OddQ@n, a[(n  1)/2], n/2]; Table[ a[n], {n, 0, 83}] (* Robert G. Wilson v, Mar 30 2006 *)
Table[BitShiftRight[n, IntegerExponent[n, 2] + 1], {n, 100}] (* IWABUCHI Yu(u)ki, Oct 13 2012 *)


PROG

(PARI) a(n)={while(n%2, n\=2); n\2} \\ M. F. Hasler, May 03 2008
(Haskell)
import Data.List
interleave xs ys = concat . transpose $ [xs, ys]
a025480 = interleave [0..] a025480
 _Cale Gibbard_, Nov 18 2009
(Haskell) Cf. comments by Worthen and Hasler.
import Data.List (transpose)
a025480 n k = a025480_tabf !! n !! k
a025480_row n = a025480_tabf !! n
a025480_tabf = iterate (\xs > concat $
transpose [xs, [length xs .. 2 * length xs  1]]) [0]
a025480_list = concat $ a025480_tabf
(Sage)
A025480 = lambda n: odd_part(n+1)//2
(Python)


CROSSREFS

Cf. A108202, A138002, A000265, A003602, A103391, A153733, A220466, A225381, A131987, A263390, A181391, A007814.


KEYWORD



AUTHOR



EXTENSIONS



STATUS

approved



