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

Function solution

project_euler/problem_008/sol3.py:76–93  ·  view source on GitHub ↗

Find the thirteen adjacent digits in the 1000-digit number n that have the greatest product and returns it.

(n: str = N)

Source from the content-addressed store, hash-verified

74
75
76def solution(n: str = N) -> int:
77 """
78 Find the thirteen adjacent digits in the 1000-digit number n that have
79 the greatest product and returns it.
80 """
81
82 largest_product = -sys.maxsize - 1
83 substr = n[:13]
84 cur_index = 13
85 while cur_index < len(n) - 13:
86 if int(n[cur_index]) >= int(substr[0]):
87 substr = substr[1:] + n[cur_index]
88 cur_index += 1
89 else:
90 largest_product = max(largest_product, str_eval(substr))
91 substr = n[cur_index : cur_index + 13]
92 cur_index += 13
93 return largest_product
94
95
96if __name__ == "__main__":

Callers 1

sol3.pyFile · 0.70

Calls 1

str_evalFunction · 0.85

Tested by

no test coverage detected