Search: gray code
|
|
A003188
|
|
Decimal equivalent of Gray code for n.
(Formerly M2250)
|
|
+40
215
|
|
|
0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 11, 9, 8, 24, 25, 27, 26, 30, 31, 29, 28, 20, 21, 23, 22, 18, 19, 17, 16, 48, 49, 51, 50, 54, 55, 53, 52, 60, 61, 63, 62, 58, 59, 57, 56, 40, 41, 43, 42, 46, 47, 45, 44, 36, 37, 39, 38, 34, 35, 33, 32, 96, 97, 99, 98, 102, 103, 101
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
0,3
|
|
COMMENTS
|
Restricts to a permutation of each {2^(i - 1) .. 2^i - 1}. - Jason Kimberley, Apr 02 2012
Invented by Emile Baudot (1845-1903), originally called a "cyclic-permuted" code. Gray codes are named after Frank Gray, who patented their use for shaft encoders in 1953. [F. Gray, "Pulse Code Communication", U.S. Patent 2,632,058, March 17, 1953.] - Robert G. Wilson v, Jun 22 2014
For n >= 2, let G_n be the graph whose vertices are labeled as 0,1,...,2^n-1, and two vertices are adjacent if and only if their binary expansions differ in exactly one bit, then a(0),a(1),...,a(2^n-1),a(0) is a Hamilton cycle in G_n. - Jianing Song, Jun 01 2022
|
|
REFERENCES
|
M. Gardner, Mathematical Games, Sci. Amer. Vol. 227 (No. 2, Feb. 1972), p. 107.
M. Gardner, Knotted Doughnuts and Other Mathematical Entertainments. Freeman, NY, 1986, p. 15.
N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).
|
|
LINKS
|
Ed Pegg, Jr., Sequence Pictures, Math Games column, Dec 08 2003 [Cached copy, with permission (pdf only)]
|
|
FORMULA
|
a(n) = n XOR floor(n/2), where XOR is the binary exclusive OR operator. - Paul D. Hanna, Jun 04 2002
G.f.: (1/(1-x)) * Sum_{k>=0} 2^k*x^2^k/(1 + x^2^(k+1)). - Ralf Stephan, May 06 2003
a(0) = 0, a(2n) = 2a(n) + [n odd], a(2n + 1) = 2a(n) + [n even]. - Ralf Stephan, Oct 20 2003
a(0) = 0, a(n) = 2 a(floor(n/2)) + mod(floor((n + 1)/2), 2).
a(0) = 0, a(n + 1) = a(n) XOR 2^A007814(n) - Jaume Simon Gispert (jaume(AT)nuem.com), Sep 11 2004
a(2^m + k) = a(2^m - k - 1) + 2^m for 0 <= k < 2^m, m >= 0.
|
|
EXAMPLE
|
For n = 13, the binary reflected Gray code representation of n is '1011' and 1011_2 = 11_10. So, a(13) = 11. - Indranil Ghosh, Jan 23 2017
|
|
MAPLE
|
with(combinat); graycode(6); # to produce first 64 terms
printf(cat(` %.6d`$64), op(map(convert, graycode(6), binary))); lprint(); # to produce binary strings
# alternative:
read("transforms"):
XORnos(n, floor(n/2)) ;
# another Maple program:
a:= n-> Bits[Xor](n, iquo(n, 2)):
|
|
MATHEMATICA
|
|
|
PROG
|
(PARI) a(n)=bitxor(n, n>>1);
(PARI) a(n)=sum(k=1, n, (-1)^((k/2^valuation(k, 2)-1)/2)*2^valuation(k, 2))
(C) int a(int n) { return n ^ (n>>1); }
(Magma) // A recursive algorithm
N := 10; s := [[]];
for n in [1..N] do
for j in [#s..1 by -1] do
Append(~s, Append(s[j], 1));
Append(~s[j], 0);
end for;
end for;
(Magma) // A direct algorithm
I2B := func< i | [b eq 1: b in IntegerToSequence(i, 2)]>;
B2I := func< s | SequenceToInteger([b select 1 else 0:b in s], 2)>;
[B2I(Xor(I2B(i), I2B(i div 2)cat[false])):i in [1..127]]; //Jason Kimberley, Apr 02 2012
(Haskell)
import Data.Bits (xor, shiftR)
a003188 n = n `xor` (shiftR n 1) :: Integer
(Python)
(Python)
(R)
maxn <- 63 # by choice
a <- 1
for(n in 1:maxn){ a[2*n ] <- 2*a[n] + (n%%2 != 0)
a[2*n+1] <- 2*a[n] + (n%%2 == 0)}
(a <- c(0, a))
(C#)
static uint a(this uint n) => (n >> 1) ^ n; // Frank Hollstein, Mar 12 2021
|
|
CROSSREFS
|
|
|
KEYWORD
|
|
|
AUTHOR
|
|
|
STATUS
|
approved
|
|
|
|
|
A005811
|
|
Number of runs in binary expansion of n (n>0); number of 1's in Gray code for n.
(Formerly M0110)
|
|
+40
212
|
|
|
0, 1, 2, 1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 3, 2, 1, 2, 3, 4, 3, 4, 5, 4, 3, 2, 3, 4, 3, 2, 3, 2, 1, 2, 3, 4, 3, 4, 5, 4, 3, 4, 5, 6, 5, 4, 5, 4, 3, 2, 3, 4, 3, 4, 5, 4, 3, 2, 3, 4, 3, 2, 3, 2, 1, 2, 3, 4, 3, 4, 5, 4, 3, 4, 5, 6, 5, 4, 5, 4, 3, 4, 5, 6, 5, 6, 7, 6, 5, 4, 5, 6, 5, 4, 5
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
0,3
|
|
COMMENTS
|
Starting with a(1) = 0 mirror all initial 2^k segments and increase by one.
a(n) gives the net rotation (measured in right angles) after taking n steps along a dragon curve. - Christopher Hendrie (hendrie(AT)acm.org), Sep 11 2002
This sequence generates A082410: (0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, ...) and A014577; identical to the latter except starting 1, 1, 0, ...; by writing a "1" if a(n+1) > a(n); if not, write "0". E.g., A014577(2) = 0, since a(3) < a(2), or 1 < 2. - Gary W. Adamson, Sep 20 2003
Starting with 1 = partial sums of A034947: (1, 1, -1, 1, 1, -1, -1, 1, 1, 1, ...). - Gary W. Adamson, Jul 23 2008
The composer Per Nørgård's name is also written in the OEIS as Per Noergaard.
Can be used as a binomial transform operator: Let a(n) = the n-th term in any S(n); then extract 2^k strings, adding the terms. This results in the binomial transform of S(n). Say S(n) = 1, 3, 5, ...; then we obtain the strings: (1), (3, 1), (3, 5, 3, 1), (3, 5, 7, 5, 3, 5, 3, 1), ...; = the binomial transform of (1, 3, 5, ...) = (1, 4, 12, 32, 80, ...). Example: the 8-bit string has a sum of 32 with a distribution of (1, 3, 3, 1) or one 1, three 3's, three 5's, and one 7; as expected. - Gary W. Adamson, Jun 21 2012
Considers all positive odd numbers as nodes of a graph. Two nodes are connected if and only if the sum of the two corresponding odd numbers is a power of 2. Then a(n) is the distance between 2n + 1 and 1. - Jianing Song, Apr 20 2019
|
|
REFERENCES
|
N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).
|
|
LINKS
|
Chandler Davis and Donald E. Knuth, Number Representations and Dragon Curves -- I and II, Journal of Recreational Mathematics, volume 3, number 2, April 1970, pages 66-81, and number 3, July 1970, pages 133-149. Reprinted with addendum in Donald E. Knuth, Selected Papers on Fun and Games, 2010, pages 571-614. Equation 3.2 g(n) = a(n-1).
|
|
FORMULA
|
a(2^k + i) = a(2^k - i + 1) + 1 for k >= 0 and 0 < i <= 2^k. - Reinhard Zumkeller, Aug 14 2001
a(2n+1) = 2a(n) - a(2n) + 1, a(4n) = a(2n), a(4n+2) = 1 + a(2n+1).
a(j+1) = a(j) + (-1)^A014707(j). - Christopher Hendrie (hendrie(AT)acm.org), Sep 11 2002
G.f.: (1/(1-x)) * Sum_{k>=0} x^2^k/(1+x^2^(k+1)). - Ralf Stephan, May 02 2003
Delete the 0, make subsets of 2^n terms; and reverse the terms in each subset to generate A088696. - Gary W. Adamson, Oct 19 2003
a(0) = 0, a(2n) = a(n) + [n odd], a(2n+1) = a(n) + [n even]. - Ralf Stephan, Oct 20 2003
a(0) = 0 then a(n) = a(floor(n/2)) + (a(floor(n/2)) + n) mod 2. - Benoit Cloitre, Jan 20 2014
|
|
EXAMPLE
|
Considered as a triangle with 2^k terms per row, the first few rows are:
1
2, 1
2, 3, 2, 1
2, 3, 4, 3, 2, 3, 2, 1
...
The n-th row becomes right half of next row; left half is mirrored terms of n-th row increased by one. - Gary W. Adamson, Jun 20 2012
|
|
MAPLE
|
local i, b, ans;
if n = 0 then
return 0 ;
end if;
ans := 1;
b := convert(n, base, 2);
for i from nops(b)-1 to 1 by -1 do
if b[ i+1 ]<>b[ i ] then
ans := ans+1
fi
od;
return ans ;
end proc:
# second Maple program:
a:= n-> add(i, i=Bits[Split](Bits[Xor](n, iquo(n, 2)))):
|
|
MATHEMATICA
|
Table[ Length[ Length/@Split[ IntegerDigits[ n, 2 ] ] ], {n, 1, 255} ]
|
|
PROG
|
(PARI) a(n)=sum(k=1, n, (-1)^((k/2^valuation(k, 2)-1)/2))
(PARI) a(n)=if(n<1, 0, a(n\2)+(a(n\2)+n)%2) \\ Benoit Cloitre, Jan 20 2014
(Haskell)
import Data.List (group)
a005811 0 = 0
a005811 n = length $ group $ a030308_row n
a005811_list = 0 : f [1] where
f (x:xs) = x : f (xs ++ [x + x `mod` 2, x + 1 - x `mod` 2])
(Python)
def a(n): return bin(n^(n>>1))[2:].count("1") # Indranil Ghosh, Apr 29 2017
|
|
CROSSREFS
|
Cf. A056539, A014707, A014577, A082410, A030308, A090079, A044813, A165413, A226227, A226228, A226229.
|
|
KEYWORD
|
|
|
AUTHOR
|
|
|
EXTENSIONS
|
|
|
STATUS
|
approved
|
|
|
|
|
A006068
|
|
a(n) is Gray-coded into n.
(Formerly M2253)
|
|
+40
153
|
|
|
0, 1, 3, 2, 7, 6, 4, 5, 15, 14, 12, 13, 8, 9, 11, 10, 31, 30, 28, 29, 24, 25, 27, 26, 16, 17, 19, 18, 23, 22, 20, 21, 63, 62, 60, 61, 56, 57, 59, 58, 48, 49, 51, 50, 55, 54, 52, 53, 32, 33, 35, 34, 39, 38, 36, 37, 47, 46, 44, 45, 40, 41, 43, 42, 127, 126, 124, 125, 120, 121
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
0,3
|
|
COMMENTS
|
Equivalently, if binary expansion of n has m bits (say), compute derivative of n (A038554), getting sequence n' of length m-1; sort on n'.
The sequence exhibits glide reflections that grow fractally. These show up well on the scatterplot, also audibly using the "listen" link. - Peter Munn, Aug 18 2019
|
|
REFERENCES
|
M. Gardner, Mathematical Games, Sci. Amer. Vol. 227 (No. 2, Feb. 1972), p. 107.
M. Gardner, Knotted Doughnuts and Other Mathematical Entertainments. Freeman, NY, 1986, p. 15.
N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).
|
|
LINKS
|
Eric Rowland and Reem Yassawi, Profinite automata, arXiv:1403.7659 [math.DS], 2014. See p. 22.
|
|
FORMULA
|
a(n) = 2*a(ceiling((n+1)/2)) + A010060(n-1). If 3*2^(k-1) < n <= 2^(k+1), a(n) = 2^(k+1) - 1 - a(n-2^k); if 2^(k+1) < n <= 3*2^k, a(n) = a(n-2^k) + 2^k. - Henry Bottomley, Jan 10 2001
a(n) = n XOR [n/2] XOR [n/4] XOR [n/8] ... XOR [n/2^m] where m = [log(n)/log(2)] (for n>0) and [x] is integer floor of x. - Paul D. Hanna, Jun 04 2002
a(n) = if n<2 then n else 2*m + (n mod 2 + m mod 2) mod 2, with m=a(floor(n/2)). - Reinhard Zumkeller, Aug 10 2010
a(n XOR m) = a(n) XOR a(m), where XOR is the bitwise exclusive-or operator, A003987. - Peter Munn, Dec 14 2019
a(0) = 0. For all n >= 0 if a(n) is even a(2*n) = 2*a(n), a(2*n+1) = 2*a(n)+1, else a(2*n) = 2*a(n)+1, a(2*n+1) = 2*a(n). - Yosu Yurramendi, Oct 12 2021
|
|
EXAMPLE
|
The first few values of n' are -,-,1,0,10,11,01,00,100,101,111,110,010,011,001,000,... (for n=0..15) and to put these in lexicographic order we must take n in the order 0,1,3,2,7,6,4,5,15,14,12,13,8,9,11,10,...
|
|
MAPLE
|
a:= proc(n) option remember; `if`(n<2, n,
Bits[Xor](n, a(iquo(n, 2))))
end:
|
|
MATHEMATICA
|
Table[Fold[BitXor, n, Quotient[n, 2^Range[BitLength[n] - 1]]], {n, 0, 70}] (* Jan Mangaldan, Mar 20 2013 *)
|
|
PROG
|
(PARI) {a(n)=local(B=n); for(k=1, floor(log(n+1)/log(2)), B=bitxor(B, n\2^k)); B} /* Paul D. Hanna, Jan 18 2012 */
(PARI) /* the following routine needs only O(log_2(n)) operations */
a(n)= {
my( s=1, ns );
while ( 1,
ns = n >> s;
if ( 0==ns, break() );
n = bitxor(n, ns);
s <<= 1;
);
return ( n );
(Haskell)
a006068 n = foldl xor 0 $
map (div n) $ takeWhile (<= n) a000079_list :: Integer
(Python)
def a(n):
s=1
while True:
ns=n>>s
if ns==0: break
n=n^ns
s<<=1
return n
(R) nmax <- 63 # by choice
a <- vector()
for(n in 1:nmax){
ones <- which(as.integer(intToBits(n)) == 1)
nbit <- as.integer(intToBits(n))[1:tail(ones, n = 1)]
level <- 0; anbit <- nbit; anbit.s <- nbit
while(sum(anbit.s) > 0){
s <- 2^level; if(s > length(anbit.s)) break
anbit.s <- c(anbit[-(1:s)], rep(0, s))
anbit <- bitwXor(anbit, anbit.s)
level <- level + 1
}
a <- c(a, sum(anbit*2^(0:(length(anbit) - 1))))
}
(a <- c(0, a))
|
|
CROSSREFS
|
A003987, A010060 are used to express relationship between terms of this sequence.
|
|
KEYWORD
|
|
|
AUTHOR
|
|
|
EXTENSIONS
|
|
|
STATUS
|
approved
|
|
|
|
|
A014550
|
|
Binary reflected Gray code.
|
|
+40
31
|
|
|
0, 1, 11, 10, 110, 111, 101, 100, 1100, 1101, 1111, 1110, 1010, 1011, 1001, 1000, 11000, 11001, 11011, 11010, 11110, 11111, 11101, 11100, 10100, 10101, 10111, 10110, 10010, 10011, 10001, 10000, 110000, 110001, 110011, 110010, 110110
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
0,3
|
|
REFERENCES
|
Gardner, M. "The Binary Gray Code." Ch. 2 in Knotted Doughnuts and Other Mathematical Entertainments. New York: W. H. Freeman, 1986.
C. A. Pickover, The Math Book, Sterling, NY, 2009; see p. 392.
|
|
LINKS
|
Eric Weisstein's World of Mathematics, Gray Code
|
|
MAPLE
|
a:= proc(n) option remember; `if`(n<2, n,
(b-> 10^b +a(2^(b+1)-1-n))(ilog2(n)))
end:
|
|
MATHEMATICA
|
|
|
PROG
|
|
|
CROSSREFS
|
|
|
KEYWORD
|
nonn,nice,easy
|
|
AUTHOR
|
|
|
EXTENSIONS
|
More terms from Larry Reeves (Larryr(AT)acm.org), Sep 05 2000
|
|
STATUS
|
approved
|
|
|
|
|
|
|
0, 1, 3, 6, 2, 12, 4, 7, 5, 24, 8, 11, 9, 13, 15, 10, 14, 48, 16, 19, 17, 21, 23, 18, 22, 25, 27, 30, 26, 20, 28, 31, 29, 96, 32, 35, 33, 37, 39, 34, 38, 41, 43, 46, 42, 36, 44, 47, 45, 49, 51, 54, 50, 60, 52, 55, 53, 40, 56, 59, 57, 61, 63, 58, 62, 192, 64, 67, 65, 69, 71, 66, 70, 73, 75, 78, 74, 68, 76, 79, 77, 81
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
0,3
|
|
LINKS
|
|
|
FORMULA
|
Other identities. For all n >= 0:
A101080(n,a(n+1)) = 1. [The Hamming distance between n and a(n+1) is always one.]
|
|
MATHEMATICA
|
A003188[n_] := BitXor[n, Floor[n/2]]; A006068[n_] := If[n == 0, 0, BitXor @@ Table[Floor[n/2^m], {m, 0, Floor[Log[2, n]]}]]; a[n_] := If[n == 0, 0, A003188[1 + A006068[n-1]]]; Table[a[n], {n, 0, 100}] (* Jean-François Alcover, Feb 23 2016 *)
|
|
PROG
|
(PARI) A003188(n) = bitxor(n, floor(n/2));
A006068(n) = if(n<2, n, {my(m = A006068(floor(n/2))); 2*m + (n%2 + m%2)%2});
(Python)
if n<2: return n
return 2*m + (n%2 + m%2)%2
(Python)
k, m = n-1, n-1>>1
while m > 0:
k ^= m
m >>= 1
|
|
CROSSREFS
|
Row 1 and column 1 of array A268715 (without the initial zero).
Cf. A268817 ("square" of this permutation).
|
|
KEYWORD
|
nonn
|
|
AUTHOR
|
|
|
STATUS
|
approved
|
|
|
|
|
|
|
0, 1, 3, 2, 10, 8, 9, 11, 15, 13, 12, 14, 6, 7, 5, 4, 20, 22, 23, 21, 17, 16, 18, 19, 27, 26, 24, 25, 29, 31, 30, 28, 60, 62, 63, 61, 57, 56, 58, 59, 51, 50, 48, 49, 53, 55, 54, 52, 36, 37, 39, 38, 46, 44, 45, 47, 43, 41, 40, 42, 34, 35, 33, 32, 160, 162, 163, 161, 165, 164, 166, 167, 175, 174, 172, 173, 169, 171, 170, 168, 136
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
0,3
|
|
COMMENTS
|
Like in binary Gray code A003188, also in this permutation the binary expansions of a(n) and a(n+1) differ always by just a single bit-position, that is, A000120(A003987(a(n),a(n+1))) = 1 for all n >= 0. Here A003987 computes bitwise-XOR of its two arguments.
|
|
LINKS
|
|
|
FORMULA
|
|
|
PROG
|
(PARI)
A057300(n) = { my(t=1, s=0); while(n>0, if(1==(n%4), n++, if(2==(n%4), n--)); s += (n%4)*t; n >>= 2; t <<= 2); (s); };
A163356(n) = if(!n, n, my(i = (#binary(n)-1)\2, f = 4^i, d = (n\f)%4, r = (n%f)); (((((2+(i%2))^d)%5)-1)*f) + if(3==d, f-1-A163356(r), A057300(A163356(r))));
|
|
CROSSREFS
|
|
|
KEYWORD
|
nonn,base
|
|
AUTHOR
|
|
|
STATUS
|
approved
|
|
|
|
|
A344341
|
|
Gray-code Niven numbers: numbers divisible by the number of 1's in their binary reflected Gray code (A005811).
|
|
+40
15
|
|
|
1, 2, 3, 4, 6, 7, 8, 9, 12, 14, 15, 16, 20, 24, 27, 28, 30, 31, 32, 33, 36, 39, 40, 42, 44, 45, 48, 51, 52, 56, 57, 60, 62, 63, 64, 68, 72, 75, 76, 80, 84, 88, 90, 92, 96, 99, 100, 104, 105, 108, 111, 112, 116, 120, 123, 124, 126, 127, 128, 129, 132, 135, 136
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
1,2
|
|
LINKS
|
Eric Weisstein's World of Mathematics, Gray Code.
|
|
EXAMPLE
|
2 is a term since its Gray code is 11 and 1+1 = 2 is a divisor of 2.
6 is a term since its Gray code is 101 and 1+0+1 = 2 is a divisor of 6.
|
|
MATHEMATICA
|
gcNivenQ[n_] := Divisible[n, DigitCount[BitXor[n, Floor[n/2]], 2, 1]]; Select[Range[150], gcNivenQ]
|
|
CROSSREFS
|
Similar sequences: A005349 (decimal), A049445 (binary), A064150 (ternary), A064438 (quaternary), A064481 (base 5), A118363 (factorial), A328208 (Zeckendorf), A328212 (lazy Fibonacci), A331085 (negaFibonacci), A333426 (primorial), A334308 (base phi), A331728 (negabinary), A342426 (base 3/2), A342726 (base i-1).
|
|
KEYWORD
|
nonn,base
|
|
AUTHOR
|
|
|
STATUS
|
approved
|
|
|
|
|
A344342
|
|
Numbers k such that k and k + 1 are both Gray-code Niven numbers (A344341).
|
|
+40
15
|
|
|
1, 2, 3, 6, 7, 8, 14, 15, 27, 30, 31, 32, 39, 44, 51, 56, 62, 63, 75, 99, 104, 111, 123, 126, 127, 128, 135, 144, 155, 159, 174, 175, 184, 185, 195, 204, 207, 215, 224, 231, 234, 235, 243, 244, 248, 254, 255, 264, 275, 284, 294, 300, 304, 305, 315, 335, 354, 375
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
1,2
|
|
LINKS
|
|
|
EXAMPLE
|
1 is a term since 1 and 2 are both Gray-code Niven numbers.
|
|
MATHEMATICA
|
gcNivenQ[n_] := Divisible[n, DigitCount[BitXor[n, Floor[n/2]], 2, 1]]; Select[Range[400], And @@ gcNivenQ[# + {0, 1}] &]
|
|
CROSSREFS
|
|
|
KEYWORD
|
nonn,base
|
|
AUTHOR
|
|
|
STATUS
|
approved
|
|
|
|
|
A344343
|
|
Starts of runs of 3 consecutive Gray-code Niven numbers (A344341).
|
|
+40
15
|
|
|
1, 2, 6, 7, 14, 30, 31, 62, 126, 127, 174, 184, 234, 243, 254, 304, 474, 483, 510, 511, 534, 543, 544, 783, 784, 903, 904, 954, 963, 1022, 1134, 1144, 1253, 1264, 1448, 1475, 1504, 1895, 1914, 1923, 1974, 2046, 2047, 2093, 2094, 2104, 2814, 2888, 2944, 3054, 3064
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
1,2
|
|
LINKS
|
|
|
EXAMPLE
|
1 is a term since 1, 2 and 3 are all Gray-code Niven numbers.
|
|
MATHEMATICA
|
gcNivenQ[n_] := Divisible[n, DigitCount[BitXor[n, Floor[n/2]], 2, 1]]; Select[Range[3000], AllTrue[# + {0, 1, 2}, gcNivenQ] &]
|
|
CROSSREFS
|
|
|
KEYWORD
|
nonn,base
|
|
AUTHOR
|
|
|
STATUS
|
approved
|
|
|
|
|
|
|
0, 1, 4, 2, 6, 8, 3, 7, 10, 12, 15, 11, 5, 13, 16, 14, 18, 20, 23, 19, 29, 21, 24, 22, 9, 25, 28, 26, 30, 32, 27, 31, 34, 36, 39, 35, 45, 37, 40, 38, 57, 41, 44, 42, 46, 48, 43, 47, 17, 49, 52, 50, 54, 56, 51, 55, 58, 60, 63, 59, 53, 61, 64, 62, 66, 68, 71, 67, 77, 69, 72, 70, 89, 73, 76, 74, 78, 80, 75, 79, 113, 81
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
0,3
|
|
LINKS
|
|
|
FORMULA
|
Other identities. For all n >= 1:
a(A128309(n)) = A128309(n)+2. [Maps any even odious number to that number + 2.]
|
|
MATHEMATICA
|
|
|
PROG
|
(PARI)
a003188(n)=bitxor(n, n>>1);
a006068(n)= {
my( s=1, ns );
while ( 1,
ns = n >> s;
if ( 0==ns, break() );
n = bitxor(n, ns);
s <<= 1;
);
return (n);
a(n)=if(n==0, 0, 1 + a003188(a006068(n) - 1)); \\ Indranil Ghosh, Jun 07 2017
(Python)
def a003188(n): return n^(n>>1)
def a006068(n):
s=1
while True:
ns=n>>s
if ns==0: break
n=n^ns
s<<=1
return n
def a(n): return 0 if n==0 else 1 + a003188(a006068(n) - 1) # Indranil Ghosh, Jun 07 2017
|
|
CROSSREFS
|
Cf. A268818 ("square" of this permutation).
|
|
KEYWORD
|
nonn
|
|
AUTHOR
|
|
|
STATUS
|
approved
|
|
|
Search completed in 0.255 seconds
|