-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem_8.py
28 lines (24 loc) · 1.54 KB
/
problem_8.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""Find the thirteen adjacent digits in the 1000-digit number that have the greatest product.
What is the value of this product?"""
X = (
"731671765313306249192251196744265747423553491949349698352031277450632623957831801698480186947885184385861560789"
"112949495459501737958331952853208805511125406987471585238630507156932909632952274430435576689664895044524452316"
"173185640309871112172238311362229893423380308135336276614282806444486645238749303589072962904915604407723907138"
"1051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947"
"5224352584907711670556013604839586446706324415722155397536978179778461740649551492908625693219784686224828397224"
"1375657056057490261407972968652414535100474821663704844031998900088952434506585412275886668811642717147992444292"
"8230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054"
"4217506941658960408071984038509624554443629812309878799272442849091888458015616609791913387549920052406368991256"
"07176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450"
)
def main(string):
"""This searches a string for the 13 consecutive digits with the greatest product"""
largest_product = 1
for i in range(1000):
digits = string[i : i + 13]
product = 1
for digit in digits:
product *= int(digit)
largest_product = max(product, largest_product)
return largest_product
print(main(X))