-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheuler11.py
50 lines (35 loc) · 932 Bytes
/
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
42
43
44
45
46
47
48
49
50
grid = [[0 for x in xrange(20)] for x in xrange(20)]
numbers = open("euler11.txt",'r')
maxMult = 0
r = 0
c = 0
for line in numbers:
row = line.rstrip().split(' ')
row = map(int,row)
for num in row:
grid[r][c] = num
c += 1
r += 1
c = 0
# in a row
for r in range(0,20):
for c in range(0,20-3):
temp = grid[r][c] * grid[r][c+1] * grid[r][c+2] * grid[r][c+3]
if temp > maxMult:
maxMult = temp
# in columns
for r in range(0,20-3):
for c in range(0,20):
temp = grid[r][c] * grid[r+1][c] * grid[r+2][c] * grid[r+3][c]
if temp > maxMult:
maxMult = temp
# in crosses
for r in range(3,20-3):
for c in range(3,20-3):
temp = grid[r-3][c-3] * grid[r-2][c-2] * grid[r-1][c-1] * grid[r][c]
if temp > maxMult:
maxMult = temp
temp = grid[r][c-3] * grid[r-1][c-2] * grid[r-2][c-1] * grid[r-3][c]
if temp > maxMult:
maxMult = temp
print maxMult