A004514 Generalized nim sum n + n in base 4.
0, 2, 0, 2, 8, 10, 8, 10, 0, 2, 0, 2, 8, 10, 8, 10, 32, 34, 32, 34, 40, 42, 40, 42, 32, 34, 32, 34, 40, 42, 40, 42, 0, 2, 0, 2, 8, 10, 8, 10, 0, 2, 0, 2, 8, 10, 8, 10, 32, 34, 32, 34, 40, 42, 40, 42, 32, 34, 32, 34, 40, 42, 40, 42, 128, 130, 128, 130, 136, 138, 136, 138, 128
Offset: 0
Links
- Reinhard Zumkeller, Table of n, a(n) for n = 0..10000
- Index entries for sequences related to Nim-sums
Programs
-
Haskell
a004514 = a063695 . (+ 1) . (* 2) -- Reinhard Zumkeller, Sep 26 2015
-
Magma
function A063694(n) if n le 1 then return n; else return 4*A063694(Floor(n/4)) + ((n mod 4) mod 2); end if; return A063694; end function; A004514:= func< n | 2*A063694(n) >; [A004514(n): n in [0..90]]; // G. C. Greubel, Dec 05 2022
-
Mathematica
A004514[n_]:= A004514[n]= If[n==0, 0, 2*n -2*A004514[Floor[n/2]]]; Table[A004514[n], {n,0,90}] (* G. C. Greubel, Dec 05 2022 *) A004514[n_] := FromDigits[ReplaceAll[IntegerDigits[2*n + 1, 4], {1 -> 0, 3 -> 2}], 4]; Array[A004514, 100, 0] (* Paolo Xausa, Feb 27 2025 *)
-
PARI
a(n) = if(n, bitand(n, 2<
Kevin Ryde, Dec 10 2022 -
Python
def A004514(n): return (n&((1<<(m:=n.bit_length())+(m&1))-1)//3)<<1 # Chai Wah Wu, Jan 30 2023
-
SageMath
def A063694(n): if (n<2): return n else: return 4*A063694(floor(n/4)) + ((n%4)%2) def A004514(n): return 2*A063694(n) [A004514(n) for n in range(91)] # G. C. Greubel, Dec 05 2022
Formula
Generalized nim sum m + n in base q: write m and n in base q and add mod q with no carries, e.g., 5 + 8 in base 3 = "21" + "22" = "10" = 1.
From Vladeta Jovovic, Feb 23 2003: (Start)
a(n) = 2*(n - a(floor(n/2))).
a(n) = 2*A063694(n). (End)
a(n) = A088442(n) - 1. - Chris Groer (cgroer(AT)math.uga.edu), Nov 10 2003
a(n) = n + A053985(n). - Reinhard Zumkeller, Dec 27 2003
a(n) = A063695(2*n+1). - Reinhard Zumkeller, Sep 26 2015
Extensions
More terms from Reinhard Zumkeller, Dec 27 2003
Comments