MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / next_number

Function next_number

project_euler/problem_092/sol1.py:17–37  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

15
16
17def 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,

Callers 1

chainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected