107 lines
3.4 KiB
Java
107 lines
3.4 KiB
Java
package com.mattrixwv.adventOfCode24;
|
|
|
|
|
|
import java.security.InvalidParameterException;
|
|
import java.util.List;
|
|
import java.util.Scanner;
|
|
import java.util.StringJoiner;
|
|
|
|
import com.mattrixwv.adventOfCode24.days.Problem;
|
|
import com.mattrixwv.adventOfCode24.days.Problem1;
|
|
import com.mattrixwv.adventOfCode24.days.Problem10;
|
|
import com.mattrixwv.adventOfCode24.days.Problem11;
|
|
import com.mattrixwv.adventOfCode24.days.Problem12;
|
|
import com.mattrixwv.adventOfCode24.days.Problem13;
|
|
import com.mattrixwv.adventOfCode24.days.Problem14;
|
|
import com.mattrixwv.adventOfCode24.days.Problem2;
|
|
import com.mattrixwv.adventOfCode24.days.Problem3;
|
|
import com.mattrixwv.adventOfCode24.days.Problem4;
|
|
import com.mattrixwv.adventOfCode24.days.Problem5;
|
|
import com.mattrixwv.adventOfCode24.days.Problem6;
|
|
import com.mattrixwv.adventOfCode24.days.Problem7;
|
|
import com.mattrixwv.adventOfCode24.days.Problem8;
|
|
import com.mattrixwv.adventOfCode24.days.Problem9;
|
|
|
|
|
|
public class ProblemSelector{
|
|
private static final Scanner input = new Scanner(System.in);
|
|
//Holds the valid problem numbers
|
|
protected static final List<Integer> PROBLEM_NUMBERS = List.of(
|
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
|
|
10, 11, 12, 13, 14
|
|
);
|
|
|
|
|
|
private ProblemSelector(){
|
|
throw new IllegalStateException("Utility class");
|
|
}
|
|
|
|
|
|
//Returns the problem corresponding to the given problem number
|
|
public static Problem getProblem(Integer dayNumber){
|
|
Problem day = null;
|
|
switch(dayNumber){
|
|
case 1 : day = new Problem1(); break;
|
|
case 2 : day = new Problem2(); break;
|
|
case 3 : day = new Problem3(); break;
|
|
case 4 : day = new Problem4(); break;
|
|
case 5 : day = new Problem5(); break;
|
|
case 6 : day = new Problem6(); break;
|
|
case 7 : day = new Problem7(); break;
|
|
case 8 : day = new Problem8(); break;
|
|
case 9 : day = new Problem9(); break;
|
|
case 10 : day = new Problem10(); break;
|
|
case 11 : day = new Problem11(); break;
|
|
case 12 : day = new Problem12(); break;
|
|
case 13 : day = new Problem13(); break;
|
|
case 14 : day = new Problem14(); break;
|
|
default: throw new InvalidParameterException();
|
|
}
|
|
return day;
|
|
}
|
|
|
|
//Print the description of a problem
|
|
public static void printDescription(Integer problemNumber){
|
|
//Get the problem
|
|
Problem day = getProblem(problemNumber);
|
|
//Print the problem's description
|
|
System.out.println(day.getDescription());
|
|
}
|
|
|
|
//Solve a problem
|
|
public static void solveProblem(Integer problemNumber){
|
|
//Get the problem
|
|
Problem problem = getProblem(problemNumber);
|
|
System.out.println("\n\n\n");
|
|
//Print the problem description
|
|
System.out.println(problem.getDescription());
|
|
//Solve the problem
|
|
problem.runSolution();
|
|
//Print the results
|
|
System.out.println(problem.getResult());
|
|
System.out.println("\n\n\n");
|
|
}
|
|
|
|
//Get a valid problem number from a user
|
|
public static Integer getProblemNumber(){
|
|
Integer problemNumber = 0;
|
|
System.out.print("Enter a problem number: ");
|
|
problemNumber = input.nextInt();
|
|
while(!PROBLEM_NUMBERS.contains(problemNumber)){
|
|
System.out.print("That is an invalid problem number!\n Enter a problem number: ");
|
|
problemNumber = input.nextInt();
|
|
}
|
|
return problemNumber;
|
|
}
|
|
|
|
//List all valid problem numbers
|
|
public static void listProblems(){
|
|
StringJoiner joiner = new StringJoiner(", ");
|
|
for(Integer num : PROBLEM_NUMBERS){
|
|
joiner.add(num.toString());
|
|
}
|
|
System.out.println(joiner.toString());
|
|
System.out.println();
|
|
}
|
|
}
|