login
The OEIS Foundation is supported by donations from users of the OEIS and by a grant from the Simons 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
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, 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, 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 (list; graph; refs; listen; history; text; internal format)
OFFSET

0,12

COMMENTS

The analog of A033665 in base 2.

LINKS

Table of n, a(n) for n=0..111.

Index entries for sequences related to Reverse and Add!

Klaus Brockhaus, On the'Reverse and Add!' algorithm in base 2

EXAMPLE

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.

MATHEMATICA

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

Table[np = n; i = 0;

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

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

If[i >= limit, -1, i], {n, 0, 111}] (* Robert Price, Oct 14 2019 *)

PROG

(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).

CROSSREFS

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

Sequence in context: A107016 A318702 A226519 * A060588 A221167 A286134

Adjacent sequences:  A066054 A066055 A066056 * A066058 A066059 A066060

KEYWORD

base,sign

AUTHOR

Klaus Brockhaus, Dec 04 2001

STATUS

approved

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

License Agreements, Terms of Use, Privacy Policy. .

Last modified May 31 22:45 EDT 2020. Contains 334756 sequences. (Running on oeis4.)