From 187dcaedd779c4966874ac6a9f8eea2d501efba7 Mon Sep 17 00:00:00 2001 From: Mattrixwv Date: Tue, 16 Jun 2020 17:48:44 -0400 Subject: [PATCH] Updated for performance --- .../ProjectEuler/Problems/Problem15.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/mattrixwv/ProjectEuler/Problems/Problem15.java b/src/main/java/mattrixwv/ProjectEuler/Problems/Problem15.java index d0d319b..22df7c4 100644 --- a/src/main/java/mattrixwv/ProjectEuler/Problems/Problem15.java +++ b/src/main/java/mattrixwv/ProjectEuler/Problems/Problem15.java @@ -1,12 +1,11 @@ //ProjectEuler/Java/Problem15.java //Matthew Ellison // Created: 03-04-19 -//Modified: 03-28-19 +//Modified: 06-16-20 //How many routes from the top left corner to the bottom right corner are there through a 20×20 grid if you can only move right and down? //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses -//This program has not been tested fully and has not even been run to completion because of the long time it takes to run /* - Copyright (C) 2019 Matthew Ellison + Copyright (C) 2020 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -26,9 +25,9 @@ package mattrixwv.ProjectEuler.Problems; public class Problem15 extends Problem{ //The width of the box to traverse - private static final Integer WIDTH = 20; + private static final int WIDTH = 20; //The height of the box to traverse - private static final Integer LENGTH = 20; + private static final int LENGTH = 20; //The number of routes from 0, 0 to 20, 20 private Long numOfRoutes = 0L; @@ -37,8 +36,8 @@ public class Problem15 extends Problem{ } public void solve(){ //Setup the rest of the variables - Integer currentX = 0; //The current x location on the grid - Integer currentY = 0; //The current y location on the grid + int currentX = 0; //The current x location on the grid + int currentY = 0; //The current y location on the grid //Start the timer timer.start(); @@ -55,7 +54,7 @@ public class Problem15 extends Problem{ } //This function acts as a handler for moving the position on the grid and counting the distance //It moves right first, then down - private void move(Integer currentX, Integer currentY){ + private void move(int currentX, int currentY){ //Check if you are at the end and act accordingly if((currentX == WIDTH) && (currentY == LENGTH)){ ++numOfRoutes; @@ -76,5 +75,5 @@ public class Problem15 extends Problem{ /* Results: The number of routes is 137846528820 -It took 26.396 minutes to solve this problem. +It took 19.764 minutes to solve this problem. */