mirror of
https://bitbucket.org/Mattrixwv/projecteulerjava.git
synced 2025-12-06 17:13:58 -05:00
Updated long running problem to test smaller dataset
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user