-
Notifications
You must be signed in to change notification settings - Fork 0
/
euler11.py
41 lines (35 loc) · 1.52 KB
/
euler11.py
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
36
37
38
39
40
41
# Каково наибольшее произведение четырех подряд идущих
# чисел в таблице 20×20, расположенных в любом направлении
# (вверх, вниз, вправо, влево или по диагонали)?
from project_euler_defs import *
n = 4
# 1 Вариант
start_time = datetime.now()
matrix = readmatrix("euler11.txt")
# Транспонирование матрицы
matrix_transpose = [[0 for j in range(len(matrix))]
for i in range(len(matrix[0]))]
for i in range(len(matrix)):
for j in range(len(matrix[0])):
matrix_transpose[j][i] = matrix[i][j]
print(max(product_multiply(matrix, n)
+ product_multiply(matrix_transpose, n)
+ [product_multiply_diagonals(matrix, n)]))
print(datetime.now() - start_time)
# 2 Вариант
start_time = datetime.now()
matrix = array(readmatrix("euler11.txt"))
matrix_transpose = matrix.transpose()
print(max(product_multiply(matrix, n)
+ product_multiply(matrix_transpose, n)
+ [product_multiply_diagonals(matrix, n)]))
print(datetime.now() - start_time)
# 3 Вариант
start_time = datetime.now()
url = 'https://euler.jakumo.org/problems/view/11.html'
matrix = array(readmatrix(text=get_data(url, 'p', 1).strip().split("\n")))
matrix_transpose = matrix.transpose()
print(max(product_multiply(matrix, n)
+ product_multiply(matrix_transpose, n)
+ [product_multiply_diagonals(matrix, n)]))
print(datetime.now() - start_time)