Ejemplo n.º 1
0
  public P67() {

    timer = new Timer();
    timer.start();

    // Initialize the matrix we'll use to store the computed values (dynamic
    // programming implementation)
    dMatrix = new BigInteger[dimension][dimension];
    for (int x = 0; x < dimension; ++x) {
      for (int y = 0; y < dimension; ++y) {
        dMatrix[x][y] = BigInteger.valueOf(-1);
      }
    }

    // Load the input matrix
    matrix = loadMatrix();

    // printMatrix();

    // Compute the most expensive path through the matrix
    computePathSum(0, 0);

    // printMatrix();

    // Stop the timer and assign the result to 'answer'
    timer.stop();
    answer = dMatrix[0][0].toString();
  }
Ejemplo n.º 2
0
 public String getAnswer() {
   StringBuilder sb = new StringBuilder();
   sb.append("Answer: The first trangle number is: ");
   sb.append(answer + " (" + divisors + " divisors)" + Constants.NEWLINE);
   sb.append(timer.getElapsedTime());
   return sb.toString();
 }
Ejemplo n.º 3
0
 public String getAnswer() {
   StringBuilder sb = new StringBuilder();
   sb.append("Answer: The maximum total is: ");
   sb.append(answer + "" + Constants.NEWLINE);
   sb.append(timer.getElapsedTime());
   return sb.toString();
 }
Ejemplo n.º 4
0
  public P12() {
    int start = 1;
    int end = 50000;

    timer = new Timer();
    timer.start();

    for (int i = start; i <= end; i++) {
      int triangleNum = getNthTriangleNumber(i);
      int numDivisors = getNumberOfDivisors(triangleNum);
      if (numDivisors >= 500) {
        answer = triangleNum;
        divisors = numDivisors;
        break;
      }
    }

    timer.stop();
  }