From d6682ab2cf4a24a5bd57f0b31b495a1c0672051d Mon Sep 17 00:00:00 2001 From: Mattrixwv Date: Tue, 16 Jun 2020 02:40:33 -0400 Subject: [PATCH] Updated for performance --- .../mattrixwv/ProjectEuler/Problems/Problem11.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/mattrixwv/ProjectEuler/Problems/Problem11.java b/src/main/java/mattrixwv/ProjectEuler/Problems/Problem11.java index f2a95c8..cd9ed7e 100644 --- a/src/main/java/mattrixwv/ProjectEuler/Problems/Problem11.java +++ b/src/main/java/mattrixwv/ProjectEuler/Problems/Problem11.java @@ -71,7 +71,7 @@ public class Problem11 extends Problem{ {04, 42, 16, 73, 38, 25, 39, 11, 24, 94, 72, 18, 8, 46, 29, 32, 40, 62, 76, 36}, {20, 69, 36, 41, 72, 30, 23, 88, 34, 62, 99, 69, 82, 67, 59, 85, 74, 04, 36, 16}, {20, 73, 35, 29, 78, 31, 90, 01, 74, 31, 49, 71, 48, 86, 81, 16, 23, 57, 05, 54}, - {01, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 01, 89, 19, 67, 48}};; + {01, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 01, 89, 19, 67, 48}}; public Problem11(){ super("What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid?"); @@ -92,12 +92,12 @@ public class Problem11 extends Problem{ timer.start(); //Loop through every row and column - for(Integer row = 0;row < 20;++row){ - for(Integer col = 0;col < grid[row].length;++col){ + for(int row = 0;row < grid.length;++row){ + for(int col = 0;col < grid[row].length;++col){ //Directional booleans to show whether you can move a certain direction - Boolean left = false; - Boolean right = false; - Boolean down = false; + boolean left = false; + boolean right = false; + boolean down = false; //Check which direction you will be able to move if((col - 3) >= 1){ @@ -189,5 +189,5 @@ public class Problem11 extends Problem{ /* Results: The greatest product of 4 numbers in a line is 70600674 The numbers are [89, 94, 97, 87] -It took 1.310 milliseconds to solve this problem. +It took 268.600 microseconds to solve this problem. */