taesik

digitRoot 본문

functions and trick/typescript_javascript

digitRoot

taesikk 2022. 1. 29. 11:49

Additive Persistence

Consider the process of taking a number, adding its digits, then adding the digits of the number derived from it, etc., until the remaining number has only one digit. The number of additions required to obtain a single digit from a number 

 is called the additive persistence of 

, and the digit obtained is called the digital root of 

.

For example, the sequence obtained from the starting number 9876 is (9876, 30, 3), so 9876 has an additive persistence of 2 and a digital root of 3. The additive persistences of the first few positive integers are 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, ... (OEIS A031286). The smallest numbers of additive persistence 

 for 

, 1, ... are 0, 10, 19, 199, 19999999999999999999999, ... (OEIS A006050).

 

Consider the process of taking a number, taking its digit sum, then adding the digits of numbers derived from it, etc., until the remaining number has only one digit. The number of additions required to obtain a single digit from a number 

 in a given base is called the additive persistence of 

, and the digit obtained is called the digital root of 

.

export function digitalRoot(n: number): number {
  return (n - 1) % 9 + 1;
}

 

REFERENCES

Hinden, H. J. "The Additive Persistence of a Number." J. Recr. Math. 7, 134-135, 1974.Sloane, N. J. A. Sequences A006050/M4683 and A031286 in "The On-Line Encyclopedia of Integer Sequences."Sloane, N. J. A. "The Persistence of a Number." J. Recr. Math. 6, 97-98, 1973.

'functions and trick > typescript_javascript' 카테고리의 다른 글

Backspaces in string  (0) 2022.01.29
Consecutive strings  (0) 2022.01.29
Coordinates Validator  (0) 2022.01.28
Count Friday 13th given year  (0) 2022.01.28
Tribonacci  (0) 2022.01.28