cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A247891 a(n) is Gray-coded in base 4 into n.

This page as a plain text file.
%I A247891 #12 Jun 22 2025 16:28:24
%S A247891 0,1,2,3,5,6,7,4,10,11,8,9,15,12,13,14,21,22,23,20,26,27,24,25,31,28,
%T A247891 29,30,16,17,18,19,42,43,40,41,47,44,45,46,32,33,34,35,37,38,39,36,63,
%U A247891 60,61,62,48,49,50,51,53,54,55,52,58,59,56,57,85,86,87,84,90
%N A247891 a(n) is Gray-coded in base 4 into n.
%C A247891 Permutation of nonnegative numbers.
%H A247891 <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>
%F A247891 a(n) = n XOR4 [n/4] XOR4 [n/16] XOR4 [n/64] ... XOR4 [n/4^m] where m = [log(n)/log(4)], [x] is integer floor of x, and XOR4 is a base 4 analog of binary exclusive-OR operator.
%F A247891 In other words, a(n) = n + [n/4] + [n/16] + ... where addition is performed in base 4 without carries. - _David Radcliffe_, Jun 22 2025
%o A247891 (Python)
%o A247891 def basexor(a, b, base):
%o A247891   result = 0
%o A247891   digit = 1
%o A247891   while a or b:
%o A247891     da = a % base
%o A247891     db = b % base
%o A247891     a //= base
%o A247891     b //= base
%o A247891     sum = (da+db) % base
%o A247891     result += sum * digit
%o A247891     digit *= base
%o A247891   return result
%o A247891 base = 4  #  2 => A006068, 3 => A105529, 10 => A226134
%o A247891 for n in range(129):
%o A247891   a = n
%o A247891   b = n//base
%o A247891   while b:
%o A247891     a = basexor(a,b, base)
%o A247891     b //= base
%o A247891   print(a, end=', ')
%o A247891 (Python)
%o A247891 def xor4(x, y): return 4*xor4(x//4, y//4) + (x+y)%4 if x else y
%o A247891 def a(n): return xor4(n, a(n//4)) if n else 0 # _David Radcliffe_, Jun 22 2025
%Y A247891 Cf. A006068 (base 2), A105529 (base 3), A226134 (base 10).
%K A247891 nonn,base
%O A247891 0,3
%A A247891 _Alex Ratushnyak_, Sep 26 2014