Class SolutionDay7

java.lang.Object
com.expedient.adventofcodejade.BaseSolution
com.expedient.adventofcodejade.solutions.year2024.SolutionDay7

public class SolutionDay7 extends BaseSolution
  • Constructor Details

  • Method Details

    • apply

      public static Set<Long> apply(Set<Long> nums, Long nextOperand, Long target, boolean partTwo)
      Takes a set of numbers, and for each number, applies both a multiplication and addition operation on it with the next operand, returning a set containing all the results, given that they're not above the target value
      Parameters:
      nums - a set of numbers
      nextOperand - the next number to multiply/add to the current numbers
      target - the target value that is not to be exceeded
      partTwo - whether to include the concatenation operator
      Returns:
      a set of results that have not exceeded the target value
    • parseInput

      public static List<Pair<Long,List<Long>>> parseInput(PuzzleInput input)
      Reads the input line by line, constructing pairs of Integer results and a List of operands for each
      Parameters:
      input - the PuzzleInput
      Returns:
      a list of Pairs of results and lists of operands
    • checkEquation

      public static boolean checkEquation(Pair<Long,List<Long>> equation, boolean partTwo)
      Checks whether the result can be found via any combination of operations on the operands
      Parameters:
      equation - the result and operands as a pair
      partTwo - whether to use the concatenation operator
      Returns:
      whether the result can be found
    • performRepairTask

      public static Long performRepairTask(PuzzleInput input, boolean partTwo)
      Finds the sum of all results that can be found via some combination of operations on the numbers provided
      Parameters:
      input - the PuzzleInput
      partTwo - whether to use the Concatenation operator
      Returns:
      the sum
    • partOne

      public Long partOne(PuzzleInput input)
      Provides the sum of equations that can be found using the given operands
      Specified by:
      partOne in class BaseSolution
      Parameters:
      input - the PuzzleInput to be used for the solution
      Returns:
      the sum of valid equations
    • partTwo

      public Long partTwo(PuzzleInput input)
      Provides the sum of equations that can be found using the given operands, allowing use of the concatenation operator
      Specified by:
      partTwo in class BaseSolution
      Parameters:
      input - the PuzzleInput to be used for the solution
      Returns:
      the sum of valid equations