Esempio n. 1
0
def horizontal_max(l, adjacent):
    largest = 0
    for line in l:
        for i in xrange(len(line) - adjacent + 1):
            current = list_product(line[i:i + adjacent])
            if current > largest:
                largest = current
    return largest
Esempio n. 2
0
def vertical_max(l, adjacent):
    largest = 0
    for column in xrange(len(l[0])):
        for row in xrange(len(l) - adjacent + 1):
            current = list_product([l[j][column]
                                   for j in range(row, row + adjacent)])
            if current > largest:
                largest = current
    return largest
Esempio n. 3
0
def left_diagonal_max(l, adjacent):
    largest = 0
    for column in xrange(adjacent - 1, len(l[0])):
        for row in xrange(len(l) - adjacent + 1):
            current = list_product([l[row + i][column - i]
                                   for i in range(adjacent)])
            if current > largest:
                largest = current
    return largest
Esempio n. 4
0
def largest_product(n):
    fin = open('pr8.txt')
    number = ''
    for line in fin:
        number += line.strip()
    l = [int(i) for i in list(str(number))]
    largest = 0
    for i in xrange(0, len(l) - n + 1):
        current_product = mathtools.list_product(l[i:i + n])
        if current_product > largest:
            largest = current_product
    return largest