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

Function solution

project_euler/problem_008/sol1.py:60–79  ·  view source on GitHub ↗

Find the thirteen adjacent digits in the 1000-digit number n that have the greatest product and returns it. >>> solution("13978431290823798458352374") 609638400 >>> solution("13978431295823798458352374") 2612736000 >>> solution("1397843129582379841238352374") 209018

(n: str = N)

Source from the content-addressed store, hash-verified

58
59
60def solution(n: str = N) -> int:
61 """
62 Find the thirteen adjacent digits in the 1000-digit number n that have
63 the greatest product and returns it.
64
65 >>> solution("13978431290823798458352374")
66 609638400
67 >>> solution("13978431295823798458352374")
68 2612736000
69 >>> solution("1397843129582379841238352374")
70 209018880
71 """
72
73 largest_product = -sys.maxsize - 1
74 for i in range(len(n) - 12):
75 product = 1
76 for j in range(13):
77 product *= int(n[i + j])
78 largest_product = max(largest_product, product)
79 return largest_product
80
81
82if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected