login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A066057 'Reverse and Add' carried out in base 2 (cf. A062128); number of steps needed to reach a palindrome, or -1 if no palindrome is ever reached. 8

%I #15 Oct 14 2019 21:09:46

%S 0,0,1,0,1,0,1,0,1,0,1,2,1,2,1,0,1,0,1,4,5,0,-1,2,1,4,-1,0,-1,2,1,0,1,

%T 0,1,-1,1,-1,1,2,1,-1,1,2,3,0,-1,-1,1,-1,3,0,1,2,3,2,1,2,3,2,-1,-1,1,

%U 0,1,0,1,-1,1,2,1,4,3,0,11,-1,5,-1,-1,2,1,2,1,4,-1,0,-1,2,5,-1,-1,2,3,0,-1,-1,1,-1,3,0,1,4,1,10,11,-1,-1,0,-1,2,-1,4

%N 'Reverse and Add' carried out in base 2 (cf. A062128); number of steps needed to reach a palindrome, or -1 if no palindrome is ever reached.

%C The analog of A033665 in base 2.

%H <a href="/index/Res#RAA">Index entries for sequences related to Reverse and Add!</a>

%H Klaus Brockhaus, <a href="/A058042/a058042.txt">On the'Reverse and Add!' algorithm in base 2</a>

%e 10011 (19 in base 10) -> 10011 + 11001 = 101100 -> 101100 + 1101 = 111001 -> 111001 + 100111 = 1100000 -> 1100000 + 11 = 1100011 (palindrome) requires 4 steps, so a(19) = 4.

%t limit = 10^4; (* Assumes that there is no palindrome if none is found before "limit" iterations *)

%t Table[np = n; i = 0;

%t While[np != IntegerReverse[np, 2] && i < limit,

%t np = np + IntegerReverse[np, 2]; i++];

%t If[i >= limit, -1, i], {n, 0, 111}] (* _Robert Price_, Oct 14 2019 *)

%o (ARIBAS): function b2reverse(a: integer): integer; var n,i,rev: integer; begin n := bit_length(a); for i := 0 to n-1 do if bit_test(a,i) = 1 then rev := bit_set(rev,n-1-i); end; end; return rev; end; function a066057(mx,stop: integer); var c,k,m,rev: integer; begin for k := 0 to mx do c := 0; m := k; rev := b2reverse(m); while m <> rev and c < stop do inc(c); m := m + rev; rev := b2reverse(m); end; if c < stop then write(c); else write(-1); end; write(" "); end; end; a066057(120,300).

%Y Cf. A033665, A058042, A062128, A062130, A033865, A061561, A066058, A006995, A057148.

%K base,sign

%O 0,12

%A _Klaus Brockhaus_, Dec 04 2001

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 19 15:34 EDT 2024. Contains 371794 sequences. (Running on oeis4.)