Blame view

8.py 549 Bytes
Imanol-Mikel Barba Sabariego authored
1
2
3
4
#!/usr/bin/python

import sys;
import math;
5
import os
Imanol-Mikel Barba Sabariego authored
6
7
def nDigitProduct(num,offset,digits):
Imanol-Mikel Barba Sabariego authored
8
9

	sum = 1;
10
	for i in range(offset,offset+digits):
Imanol-Mikel Barba Sabariego authored
11
12
13
14
		sum *= int(num[i]);

	return sum;
15
def greatestProduct(num,digits):
Imanol-Mikel Barba Sabariego authored
16
17

	higherProduct = 0;
18
19
	for i in range (0, len(num)-(digits-1)):
		product = nDigitProduct(num,i,digits);
Imanol-Mikel Barba Sabariego authored
20
21
22
23
24
		if(product > higherProduct):
			higherProduct = product;

	return higherProduct;
25
26
27
strNum = "".join(sys.stdin.readlines()).replace('\n','')
numDigits = int(sys.argv[1])
print "Result is: " + str(greatestProduct(strNum,numDigits));