Updated long running problem to test smaller dataset

This commit is contained in:
2022-12-06 18:41:20 -05:00
parent 5bdb9f8110
commit d48d245110
6 changed files with 50 additions and 37 deletions

View File

@@ -26,15 +26,15 @@ package com.mattrixwv.project_euler.problems;
public class Problem15 extends Problem{
//Variables
//Static vaiables
private static final int WIDTH = 20; //The width of the box to traverse
private static final int LENGTH = 20; //The height of the box to traverse
protected static int gridWidth = 20; //The width of the box to traverse
protected static int gridLength = 20; //The height of the box to traverse
//Instance variables
private long numOfRoutes; //The number of routes from 0, 0 to 20, 20
//Functions
//Constructor
public Problem15(){
super(String.format("How many routes from the top left corner to the bottom right corner are there through a %dx%d grid if you can only move right and down?", WIDTH, LENGTH));
super(String.format("How many routes from the top left corner to the bottom right corner are there through a %dx%d grid if you can only move right and down?", gridWidth, gridLength));
numOfRoutes = 0;
}
//Operational functions
@@ -65,18 +65,18 @@ public class Problem15 extends Problem{
//It moves right first, then down
private void move(int currentX, int currentY){
//Check if you are at the end and act accordingly
if((currentX == WIDTH) && (currentY == LENGTH)){
if((currentX == gridWidth) && (currentY == gridLength)){
++numOfRoutes;
return;
}
//Move right if possible
if(currentX < WIDTH){
if(currentX < gridWidth){
move(currentX + 1, currentY);
}
//Move down if possible
if(currentY < LENGTH){
if(currentY < gridLength){
move(currentX, currentY + 1);
}
}