mirror of
https://bitbucket.org/Mattrixwv/projecteulerjava.git
synced 2025-12-07 01:23:56 -05:00
Updated for performance
This commit is contained in:
@@ -1,12 +1,11 @@
|
|||||||
//ProjectEuler/Java/Problem15.java
|
//ProjectEuler/Java/Problem15.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 03-04-19
|
// 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?
|
//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
|
//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
|
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
|
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{
|
public class Problem15 extends Problem{
|
||||||
//The width of the box to traverse
|
//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
|
//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
|
//The number of routes from 0, 0 to 20, 20
|
||||||
private Long numOfRoutes = 0L;
|
private Long numOfRoutes = 0L;
|
||||||
|
|
||||||
@@ -37,8 +36,8 @@ public class Problem15 extends Problem{
|
|||||||
}
|
}
|
||||||
public void solve(){
|
public void solve(){
|
||||||
//Setup the rest of the variables
|
//Setup the rest of the variables
|
||||||
Integer currentX = 0; //The current x location on the grid
|
int currentX = 0; //The current x location on the grid
|
||||||
Integer currentY = 0; //The current y location on the grid
|
int currentY = 0; //The current y location on the grid
|
||||||
|
|
||||||
//Start the timer
|
//Start the timer
|
||||||
timer.start();
|
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
|
//This function acts as a handler for moving the position on the grid and counting the distance
|
||||||
//It moves right first, then down
|
//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
|
//Check if you are at the end and act accordingly
|
||||||
if((currentX == WIDTH) && (currentY == LENGTH)){
|
if((currentX == WIDTH) && (currentY == LENGTH)){
|
||||||
++numOfRoutes;
|
++numOfRoutes;
|
||||||
@@ -76,5 +75,5 @@ public class Problem15 extends Problem{
|
|||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The number of routes is 137846528820
|
The number of routes is 137846528820
|
||||||
It took 26.396 minutes to solve this problem.
|
It took 19.764 minutes to solve this problem.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user