/python/largest-series-product/series.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
def largest_product(digits, n):
    """
    Return the largest product for an n-length slice of digits
    """
    groups = slices(digits, n)

    return max(reduce(lambda a, b: a * b, g, 1) for g in groups)


def slices(digits, n):
    """
    Return list of all possible n-length slices of digits
    """
    if n > len(digits):
        raise ValueError("Sequence is too short")

    return [map(int, digits[i:i+n])
            for i in range(0, len(digits)-n+1)]

@manurFR thinks this looks great

Comments


You're not logged in right now. Please login via GitHub to comment