일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- manifest.json
- useEffect
- java api
- Debug
- TypeScript
- type
- descendingOrder
- DB2
- codewar
- IBM
- isSquare
- custom hook
- JDBC
- react
- react hook
- TABLESPACE
- codewars
- Today
- Total
taesik
digitRoot 본문
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 |