Skip to content

Commit d60d3a7

Browse files
authored
Problem 8
Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?
1 parent 5272ba0 commit d60d3a7

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

Problem 8

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import urllib.request
2+
import time
3+
4+
#start timer
5+
start = time.time()
6+
7+
#import the problem to access the number easier
8+
url = "https://projecteuler.net/problem=8"
9+
data = urllib.request.urlopen(url).read()
10+
data1 = str(data)
11+
#assemble the number from the page readout prints in block readout
12+
locationTracker = data1.find("73167")
13+
bigNumber = data1[data1.find("73167"):data1.find("73167")+50]
14+
for j in range(0,19):
15+
locationTracker = locationTracker + 58
16+
bigNumber += data1[locationTracker:locationTracker+50]
17+
18+
#multiply a string of 13 numbers
19+
def multiplyNums(string):
20+
finalProduct = 1
21+
for index in range(13):
22+
finalProduct *= int(string[index:index+1])
23+
return finalProduct
24+
25+
#main
26+
maxProduct = 0
27+
for index in range(988):
28+
newProduct = multiplyNums(bigNumber[index:index+13])
29+
if (newProduct>maxProduct):
30+
maxProduct = newProduct
31+
32+
#end timer
33+
end = time.time()
34+
35+
#prints results
36+
print("Time: " + str(end - start))
37+
print("Solution: " + str(maxProduct))

0 commit comments

Comments
 (0)