A010888 Digital root of n (repeatedly add the digits of n until a single digit is reached).
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5
Offset: 0
Examples
The digits of 37 are 3 and 7, and 3 + 7 = 10. And the digits of 10 are 1 and 0, and 1 + 0 = 1, so a(37) = 1.
References
- Martin Gardner, Mathematics, Magic and Mystery, 1956.
Links
- N. J. A. Sloane, Table of n, a(n) for n = 0..10000
- Eric Weisstein's World of Mathematics, Digitaddition
- Eric Weisstein's World of Mathematics, Digital Root
- Wikipedia, Vedic square
- Index entries for Colombian or self numbers and related sequences
- Index entries for linear recurrences with constant coefficients, signature (0,0,0,0,0,0,0,0,1).
Crossrefs
Programs
-
Haskell
a010888 = until (< 10) a007953 -- Reinhard Zumkeller, Oct 17 2011, May 12 2011
-
Magma
[n eq 0 select 0 else 1+(n-1) mod 9: n in [0..110]]; // Bruno Berselli, Mar 18 2016
-
Maple
A010888 := n->if n=0 then 0 else ((n-1) mod 9) + 1; fi; # N. J. A. Sloane, Feb 20 2013
-
Mathematica
Join[{0}, Array[Mod[ # - 1, 9] + 1 &, 104]] (* Robert G. Wilson v, Jan 04 2006 *) Join[Range[0, 1], Table[n - 9 Floor[(n - 1) / 9], {n, 2, 100}]] (* José de Jesús Camacho Medina, Nov 10 2014 *) (* Corrected by Vincenzo Librandi, Nov 11 2014 *) Join[{0},LinearRecurrence[{0, 0, 0, 0, 0, 0, 0, 0, 1},{1, 2, 3, 4, 5, 6, 7, 8, 9},104]] (* Ray Chandler, Aug 26 2015 *) Table[FixedPoint[Total[IntegerDigits[#, 10]] &, n], {n, 0, 104}] (* IWABUCHI Yu(u)ki, Jun 03 2016 *)
-
PARI
A010888(n)=if(n,(n-1)%9+1) \\ M. F. Hasler, Jan 04 2011
-
Python
def A010888(n): return 1 + (n - 1) % 9 if n else 0 # Chai Wah Wu, Aug 23 2014, Apr 23 2023
-
Scala
0 :: List.fill(10)(1 to 9).flatten // Alonso del Arte, Feb 01 2020
Formula
If n = 0 then a(n) = 0; otherwise a(n) = (n reduced mod 9), but if the answer is 0 change it to 9.
Equivalently, if n = 0 then a(n) = 0, otherwise a(n) = (n - 1 reduced mod 9) + 1.
If the initial 0 term is ignored, the sequence is periodic with period 9.
From Hieronymus Fischer, Jun 08 2007: (Start)
a(n) = A010878(n-1) + 1 (for n > 0).
G.f.: g(x) = x*(Sum_{k = 0..8}(k+1)*x^k)/(1 - x^9). Also: g(x) = x(9x^10 - 10x^9 + 1)/((1 - x^9)(1 - x)^2). (End)
a(n) = n - 9*floor((n-1)/9), for n > 0. - José de Jesús Camacho Medina, Nov 10 2014
Comments