Exemplo n.º 1
0
  /**
   * Standard point of execution.
   *
   * @param args - not used
   */
  public static void main(String[] args) {

    Problem curProb = new PE0059();
    String result = curProb.getResult();

    IO.info("result for problem #" + curProb);
    IO.info(" is '" + result + "'");
    IO.infoln(" found in " + curProb.getRuntime(2) + " ms");
  }
Exemplo n.º 2
0
  /**
   * Runs the algorithm of the "Sieve of Eratosthenes" and count every found prime factor. If the
   * 10001. is found, it is returned.
   *
   * @return the 100001. prime factor
   * @see Sieve#next()
   * @see <a href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes">Sieve of Eratosthenes @
   *     Wikipedia</a>
   */
  @Override
  public String solve() {

    while (sieve.hasNext() && cnt < 9999) {
      cnt++;
      IO.infoln(cnt + ". prime = " + sieve.next());
    }

    return IO.i2s(sieve.next());
  }
Exemplo n.º 3
0
  /**
   * This method solves the given problem by {@link Mathe#getAlphabeticalValue(String) calculating
   * the alphabetical value} for every name in the {@link #names local memory}.
   *
   * @return the sum of all name scores
   * @see Mathe#getAlphabeticalValue(String)
   */
  @Override
  public String solve() {
    long res = 0;

    for (int i = 0; i < names.length; i++) {
      res += (i + 1) * Mathe.getAlphabeticalValue(names[i]);
    }

    return IO.l2s(res);
  }
Exemplo n.º 4
0
  /**
   * Calculating the result by running 2 nested loops and adding all products, but ignoring the
   * squares.
   *
   * @return the difference of the sum squares
   */
  @Override
  public String solve() {

    int max = 100, sum = 0;

    for (int i = 1; i <= max; i++) {
      for (int j = 1; j <= max; j++) {
        if (i != j) { // ignore squares
          sum += (i * j);
        }
      }
    }

    return IO.i2s(sum);
  }
Exemplo n.º 5
0
  /**
   * This method solves the given problem by running two nested loops to check all ten-thousand
   * combinations of a and b.
   *
   * @return the maximum found digit sum
   */
  @Override
  public String solve() {

    LargeNumber max = new LargeNumber(1);

    for (int a = 1; a < 100; a++) {
      LargeNumber lA = new LargeNumber(a);
      LargeNumber cur = lA.clone();
      for (int b = 1; b < 100; b++) {
        LargeNumber sum = cur.sumOfDigits();
        if (max.compareTo(sum) == -1) {
          IO.debugln("found new max = " + sum + " for " + a + "^" + b);
          max = sum;
        }
        cur = cur.mult(lA);
      }
    }

    return max.toString();
  }
Exemplo n.º 6
0
 /**
  * Reads the names from a file into the {@link #names local array}.
  *
  * @see IO#readSortedStrings(String)
  */
 @Override
 public void prepare() {
   super.prepare();
   names = IO.readSortedStrings("data-files/5000names.txt");
 }