Skip to content

Instantly share code, notes, and snippets.

@Atala
Created December 17, 2013 09:00
Show Gist options
  • Save Atala/8002033 to your computer and use it in GitHub Desktop.
Save Atala/8002033 to your computer and use it in GitHub Desktop.
This is my solution to the projecteuler 11th problem
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