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

Function chain

project_euler/problem_092/sol1.py:54–80  ·  view source on GitHub ↗

The function generates the chain of numbers until the next number is 1 or 89. For example, if starting number is 44, then the function generates the following chain of numbers: 44 → 32 → 13 → 10 → 1 → 1. Once the next number generated is 1 or 89, the function returns whether

(number: int)

Source from the content-addressed store, hash-verified

52
53
54def chain(number: int) -> bool:
55 """
56 The function generates the chain of numbers until the next number is 1 or 89.
57 For example, if starting number is 44, then the function generates the
58 following chain of numbers:
59 44 → 32 → 13 → 10 → 1 → 1.
60 Once the next number generated is 1 or 89, the function returns whether
61 or not the next number generated by next_number() is 1.
62 >>> chain(10)
63 True
64 >>> chain(58)
65 False
66 >>> chain(1)
67 True
68 """
69
70 if CHAINS[number - 1] is not None:
71 return CHAINS[number - 1] # type: ignore[return-value]
72
73 number_chain = chain(next_number(number))
74 CHAINS[number - 1] = number_chain
75
76 while number < 10000000:
77 CHAINS[number - 1] = number_chain
78 number *= 10
79
80 return number_chain
81
82
83def solution(number: int = 10000000) -> int:

Callers 2

test_hand_sortedFunction · 0.85
solutionFunction · 0.85

Calls 1

next_numberFunction · 0.85

Tested by 1

test_hand_sortedFunction · 0.68