File tree Expand file tree Collapse file tree 1 file changed +12
-13
lines changed
project_euler/problem_095 Expand file tree Collapse file tree 1 file changed +12
-13
lines changed Original file line number Diff line number Diff line change @@ -112,23 +112,22 @@ def find_longest_chain(chain: list[int], max_num: int) -> int:
112112 6
113113 """
114114
115- length_max = 0
116- elem_max = 0
117- for i in range (2 , len (chain )):
118- start = i
115+ max_len = 0
116+ min_elem = 0
117+ for start in range (2 , len (chain )):
118+ elem = chain [ start ]
119119 length = 1
120- el = chain [i ]
121- visited = {i }
122- while el > 1 and el <= max_num and el not in visited :
120+ visited = {start }
121+ while elem > 1 and elem <= max_num and elem not in visited :
123122 length += 1
124- visited .add (el )
125- el = chain [el ]
123+ visited .add (elem )
124+ elem = chain [elem ]
126125
127- if el == start and length > length_max :
128- length_max = length
129- elem_max = start
126+ if elem == start and length > max_len :
127+ max_len = length
128+ min_elem = start
130129
131- return elem_max
130+ return min_elem
132131
133132
134133def solution (max_num : int = 1000000 ) -> int :
You can’t perform that action at this time.
0 commit comments