-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEuler008a.py
39 lines (33 loc) · 1.61 KB
/
Euler008a.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
29
30
31
32
33
34
35
36
37
38
39
# Solution to Project Euler problem 8 by tdnzr.
# Initial, inefficient solution:
# It creates and saves ~1000 13-number strings and computes the product anew for each one.
def run():
numberString = "731671765313306249192251196744265747423553\
491949349698352031277450632623957831801698480186947885184385\
861560789112949495459501737958331952853208805511125406987471\
585238630507156932909632952274430435576689664895044524452316\
173185640309871112172238311362229893423380308135336276614282\
806444486645238749303589072962904915604407723907138105158593\
079608667017242712188399879790879227492190169972088809377665\
727333001053367881220235421809751254540594752243525849077116\
705560136048395864467063244157221553975369781797784617406495\
514929086256932197846862248283972241375657056057490261407972\
968652414535100474821663704844031998900088952434506585412275\
886668811642717147992444292823086346567481391912316282458617\
866458359124566529476545682848912883142607690042242190226710\
556263211111093705442175069416589604080719840385096245544436\
298123098787992724428490918884580156166097919133875499200524\
063689912560717606058861164671094050775410022569831552000559\
3572972571636269561882670428252483600823257530420752963450"
listOfThirteens = []
for i in range(len(numberString)-13):
listOfThirteens.append(numberString[i:i+13])
listOfProducts = []
for number in listOfThirteens: # e.g. "12345678..."
product = 1
for digit in number: # e.g. "1"
product *= int(digit)
listOfProducts.append(product)
return max(listOfProducts)
if __name__ == "__main__":
print(run())