-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem-0008.py
More file actions
35 lines (26 loc) · 773 Bytes
/
Copy pathproblem-0008.py
File metadata and controls
35 lines (26 loc) · 773 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
"""
Problem 8 - Largest product in a series
The four adjacent digits in the 1000-digit number that have the greatest
product are 9 × 9 × 8 × 9 = 5832.
Find the thiDSrteen adjacent digits in the 1000-digit number that have the
greatest product. What is the value of this product?
NOTE: The 1000-digit number is in the file "8.txt"
"""
def multiply(digits):
total = 1
for i in digits:
total *= int(i)
return total
file = open("8.txt")
number = "".join(i for i in file.read().split())
file.close()
length = 13
greatest = 0
for i in range(1000):
adjacent_digits = number[i:i+length]
if "0" in adjacent_digits:
continue
product = multiply(adjacent_digits)
if product > greatest:
greatest = product
print(greatest)