[Project Euler Problem 8]Largest product in a series

2015. 7. 16. 03:04
def prod(lst):
    rst = 1
    for i in lst:
        rst *= i
    return rst
def push(lst, end):
    for i in range(len(lst)-1):
        lst[i] = lst[i+1]
    lst[len(lst)-1] = end
    return lst

f = open("in8.txt")
xs = [1]*13
rst = 1

for line in f:
    for i in line:
        if i != '\n':
            xs = push(xs, int(i))
            r = prod(xs)
            if r > rst:
                rst = r
print rst

소스파일과 같은 디렉토리에 in8.txt라는 이름으로 주어진 숫자들을 저장하고, 위 코드를 실행시키면 됩니다.

Algorithm/Project Euler