-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem11.py
More file actions
48 lines (38 loc) · 1.03 KB
/
problem11.py
File metadata and controls
48 lines (38 loc) · 1.03 KB
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
42
43
44
45
46
47
48
# Problem 11
import numpy as np
a = np.loadtxt('nums_for_11.txt')
# Find Max Column product
col_max = 0
for i in range(16):
b = a[i:i+4,:].prod(axis = 0)
c = b.max()
if c > col_max:
col_max = c
print('Max Column Prod: %i' %col_max)
# Find Max Row product
row_max = 0
for i in range(16):
b = a[:,i:i+4].prod(axis = 1)
c = b.max()
if c > row_max:
row_max = c
print('Max Column Prod: %i' %row_max)
# Now, Find the max diagonal. This one will be harder... but with clever use
# of diagonals it is not too bad
down_col = 0
for i in range(-16, 17):
diag = np.diag(a, i)
for j in range(17 - abs(i)):
num = diag[j:j+4].prod()
if num > down_col:
down_col = num
print('Max Down Col: %i' %down_col)
up_col = 0
for i in range(-16, 17):
diag = np.diag(a[:, ::-1], i)
for j in range(17 - abs(i)):
num = diag[j:j+4].prod()
if num > up_col:
up_col = num
print('Max up Col: %i' %up_col)
print('Max: %i' %max([up_col, down_col, row_max, col_max]))