Returns the next number of the chain by adding the square of each digit to form a new number. For example, if number = 12, next_number() will return 1^2 + 2^2 = 5. Therefore, 5 is the next number of the chain. >>> next_number(44) 32 >>> next_number(10) 1 >>> next
(number: int)
| 15 | |
| 16 | |
| 17 | def next_number(number: int) -> int: |
| 18 | """ |
| 19 | Returns the next number of the chain by adding the square of each digit |
| 20 | to form a new number. |
| 21 | For example, if number = 12, next_number() will return 1^2 + 2^2 = 5. |
| 22 | Therefore, 5 is the next number of the chain. |
| 23 | >>> next_number(44) |
| 24 | 32 |
| 25 | >>> next_number(10) |
| 26 | 1 |
| 27 | >>> next_number(32) |
| 28 | 13 |
| 29 | """ |
| 30 | |
| 31 | sum_of_digits_squared = 0 |
| 32 | while number: |
| 33 | # Increased Speed Slightly by checking every 5 digits together. |
| 34 | sum_of_digits_squared += DIGITS_SQUARED[number % 100000] |
| 35 | number //= 100000 |
| 36 | |
| 37 | return sum_of_digits_squared |
| 38 | |
| 39 | |
| 40 | # There are 2 Chains made, |