-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlargestProductInSeries.py
More file actions
29 lines (27 loc) · 987 Bytes
/
largestProductInSeries.py
File metadata and controls
29 lines (27 loc) · 987 Bytes
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
#! python
import sys
print(sys.version)
import math
import time
'''
The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832.
This program intends to find the greatest product of thirteen adjacent digits in the 1000-digit number.
'''
digitGroupLength = int(input("Enter the length of series : "))
startTime = time.time() # Start timer
f = open('thousandOaks.txt', 'r')
thousandOaks = f.read()
splitOaks = list(thousandOaks)
finalProduct = 1
finalDigitGroup = []
for x in range(len(splitOaks)-digitGroupLength):
digitGroup = splitOaks[x:(x+digitGroupLength):1]
product = 1
for digit in digitGroup:
product = product * int(digit)
if product > finalProduct:
finalProduct = product
finalDigitGroup = digitGroup
print("Largest product is : "+ str(finalProduct))
print("Adjacent digits are : " + str(finalDigitGroup))
print("Time Required for execution : " + str(time.time()-startTime))