-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem8.py
More file actions
47 lines (31 loc) · 844 Bytes
/
problem8.py
File metadata and controls
47 lines (31 loc) · 844 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Problem 7
#
# Find the greatest product of five consecutive digits in the 1000-digit number. see problem8.txt
#
# @date 12/03/2012
# @author Ciarán McCann
# @website http://ciaranmccann.me/
def chunk(collection, chuckSize):
return [collection[i:i+chuckSize] for i in range(0, len(collection), chuckSize)]
def printGridArray(array,width = 10):
rows = chunk(array,width)
print(" ")
for row in rows:
print(row)
print(" ")
digits = []
with open("problem8.txt") as file:
data = file.readlines()
file.close()
for line in data:
for digit in line.strip():
digits.append(int(digit))
largest = -1
total = 1
index = 0
while index < len(digits)-5:
total = digits[index ] * digits[index +1] * digits[index +2] * digits[index +3] * digits[index +4]
if total > largest:
largest = total
index += 1
print(largest)