From 4b58a887324ce6c5fc9b36766be9b3b742c44d3c Mon Sep 17 00:00:00 2001 From: shivg7706 Date: Thu, 26 Apr 2018 08:49:55 +0530 Subject: [PATCH] another sol for 11 --- Project Euler/Problem 11/sol2.py | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Project Euler/Problem 11/sol2.py diff --git a/Project Euler/Problem 11/sol2.py b/Project Euler/Problem 11/sol2.py new file mode 100644 index 000000000..b03395f01 --- /dev/null +++ b/Project Euler/Problem 11/sol2.py @@ -0,0 +1,39 @@ +def main(): + with open ("grid.txt", "r") as f: + l = [] + for i in range(20): + l.append([int(x) for x in f.readline().split()]) + + maximum = 0 + + # right + for i in range(20): + for j in range(17): + temp = l[i][j] * l[i][j+1] * l[i][j+2] * l[i][j+3] + if temp > maximum: + maximum = temp + + # down + for i in range(17): + for j in range(20): + temp = l[i][j] * l[i+1][j] * l[i+2][j] * l[i+3][j] + if temp > maximum: + maximum = temp + + #diagonal 1 + for i in range(17): + for j in range(17): + temp = l[i][j] * l[i+1][j+1] * l[i+2][j+2] * l[i+3][j+3] + if temp > maximum: + maximum = temp + + #diagonal 2 + for i in range(17): + for j in range(3, 20): + temp = l[i][j] * l[i+1][j-1] * l[i+2][j-2] * l[i+3][j-3] + if temp > maximum: + maximum = temp + print(maximum) + +if __name__ == '__main__': + main() \ No newline at end of file