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

@@ -32,15 +32,15 @@ import java.util.List;
public class Problem24 extends Problem{
//Variables
//Static variables
private static final int NEEDED_PERM = 1000000; //The number of the permutation that you need
private static String nums = "0123456789"; //All of the characters that we need to get the permutations of
protected static int neededPerm = 1000000; //The number of the permutation that you need
protected static String nums = "0123456789"; //All of the characters that we need to get the permutations of
//Instance variables
private List<String> permutations; //Holds all of the permutations of the string nums
//Functions
//Constructor
public Problem24(){
super(String.format("What is the millionth lexicographic permutation of the digits %s?", nums));
super(String.format("What is the %dth lexicographic permutation of the digits %s?", neededPerm, nums));
permutations = new ArrayList<>();
}
//Operational functions
@@ -77,7 +77,7 @@ public class Problem24 extends Problem{
@Override
public String getResult(){
solvedCheck("result");
return String.format("The 1 millionth permutation is %s", permutations.get(NEEDED_PERM - 1));
return String.format("The %dth permutation is %s", neededPerm, permutations.get(neededPerm - 1));
}
//Returns an ArrayList with all of the permutations
public List<String> getPermutationsList(){
@@ -87,7 +87,7 @@ public class Problem24 extends Problem{
//Returns the requested permutation
public String getPermutation(){
solvedCheck("1,000,000th permutation");
return permutations.get(NEEDED_PERM - 1);
return permutations.get(neededPerm - 1);
}
}