-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD8.py
37 lines (30 loc) · 1.55 KB
/
D8.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
# Problem 8: Largest product in a series
import timeit
import math
def split_word(w):
return [int(c) for c in w]
def largest_product(n):
max_prod = 0
for i in range(0, len(number)):
if math.prod(number[i:i+n]) > max_prod:
max_prod = math.prod(number[i:i+n])
return(max_prod)
# run
start = timeit.default_timer()
number='731671765313306249192251196744265747423553491949349698352031277450632\
6239578318016984801869478851843858615607891129494954595017379583319528\
53208805511125406987471585238630507156932909632952274430435576689664895\
044524452316173185640309871112172238311362229893423380308135336276614282\
8064444866452387493035890729629049156044077239071381051585930796086670172\
42712188399879790879227492190169972088809377665727333001053367881220235421\
809751254540594752243525849077116705560136048395864467063244157221553975369\
7817977846174064955149290862569321978468622482839722413756570560574902614079\
72968652414535100474821663704844031998900088952434506585412275886668811642717\
147992444292823086346567481391912316282458617866458359124566529476545682848912\
8831426076900422421902267105562632111110937054421750694165896040807198403850962\
45544436298123098787992724428490918884580156166097919133875499200524063689912560\
717606058861164671094050775410022569831552000559357297257163626956188267042825248\
360082325753042075296345'
number=split_word(number)
print(largest_product(13))
print(timeit.default_timer() - start)