Created
December 17, 2013 09:00
-
-
Save Atala/8002033 to your computer and use it in GitHub Desktop.
This is my solution to the projecteuler 11th problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import stdin | |
def up(x, y, f): | |
try: | |
return reduce(lambda u,v: int(u)*int(v), f[x][y:y+4]) | |
except IndexError: | |
return 0 | |
def down(x, y, f): | |
try: | |
return reduce(lambda u,v: int(u)*int(v), f[x][y:y+4]) | |
except IndexError: | |
return 0 | |
def right(x, y, f): | |
try: | |
l = [ f[x+u][y] for u in range(0,4)] | |
return reduce(lambda u,v: int(u)*int(v), l) | |
except IndexError: | |
return 0 | |
def left(x, y, f): | |
try: | |
l = [ f[x+u][y] for u in range(-3,1)] | |
return reduce(lambda u,v: int(u)*int(v), l) | |
except IndexError: | |
return 0 | |
def upright(x, y, f): | |
try: | |
l = [ f[x+u][y+u] for u in range(0,4)] | |
return reduce(lambda u,v: int(u)*int(v), l) | |
except IndexError: | |
return 0 | |
def downleft(x, y, f): | |
try: | |
l = [ f[x+u][y-u] for u in range(0,4)] | |
return reduce(lambda u,v: int(u)*int(v), l) | |
except IndexError: | |
return 0 | |
if __name__ == '__main__': | |
f = [ line.strip().split(' ') for line in stdin.readlines()] | |
result = 0 | |
for x in xrange(len(f) - 1): | |
for y in xrange(len(f) - 1): | |
temp = max([up(x,y,f),down(x,y,f),right(x,y,f),left(x,y,f),upright(x,y,f),downleft(x,y,f)]) | |
if temp > result: | |
result = temp | |
print '\n', result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment