-
Notifications
You must be signed in to change notification settings - Fork 0
/
11.py
104 lines (79 loc) · 1.88 KB
/
11.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
w, h = 20, 20
matrix = [[0 for x in range(w)] for y in range(h)]
def getWords(line):
words = []
word = ''
for i in range(len(line)):
if line[i] == ' ':
words.append(word)
word = ''
else:
word += line[i]
return words
fin = open('data/input_11.txt', 'r')
i = 0
for line in fin:
j = 0
for word in getWords(line):
matrix[i][j] = int(word)
j += 1
i += 1
fin.close()
def checkTop(row, col):
product = 1
for i in range(4):
if row - i > 0:
product = product * matrix[row - i][col]
return product
def checkBot(row, col):
product = 1
for i in range(4):
if row + i < 20:
product = product * matrix[row + i][col]
return product
def checkLeft(row, col):
product = 1
for i in range(4):
if col - i > 0:
product = product * matrix[row][col -i]
return product
def checkRight(row, col):
product = 1
for i in range(4):
if col + i < 20:
product = product * matrix[row][col + i]
return product
def topLeft(row, col):
product = 1
for i in range(4):
if row - i > 0 and col - i > 0:
product = product * matrix[row - i][col - i]
return product
def topRight(row, col):
product = 1
for i in range(4):
if row - i > 0 and col + i < 20:
product = product * matrix[row - i][col + i]
return product
def botLeft(row, col):
product = 1
for i in range(4):
if row + i < 20 and col - i > 0:
product = product * matrix[row + i][col - i]
return product
def botRight(row, col):
product = 1
for i in range(4):
if row + i < 20 and col + i < 20:
product = product * matrix[row + i][col + i]
return product
funcs = [checkTop, checkBot, checkLeft, checkRight, topLeft, topRight, botLeft, botRight]
product = 1
for i in range(20):
for j in range(20):
for k in range(8):
tmp = funcs[k](i,j)
if tmp > product:
product = tmp
print product
# 70600674