-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem 8
37 lines (31 loc) · 983 Bytes
/
Problem 8
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
import urllib.request
import time
#start timer
start = time.time()
#import the problem to access the number easier
url = "https://projecteuler.net/problem=8"
data = urllib.request.urlopen(url).read()
data1 = str(data)
#assemble the number from the page readout prints in block readout
locationTracker = data1.find("73167")
bigNumber = data1[data1.find("73167"):data1.find("73167")+50]
for j in range(0,19):
locationTracker = locationTracker + 58
bigNumber += data1[locationTracker:locationTracker+50]
#multiply a string of 13 numbers
def multiplyNums(string):
finalProduct = 1
for index in range(13):
finalProduct *= int(string[index:index+1])
return finalProduct
#main
maxProduct = 0
for index in range(988):
newProduct = multiplyNums(bigNumber[index:index+13])
if (newProduct>maxProduct):
maxProduct = newProduct
#end timer
end = time.time()
#prints results
print("Time: " + str(end - start))
print("Solution: " + str(maxProduct))