package il.co.site_building.euler_45_solver;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Guy Yafe
 */
public class SimpleSolver {

  public static void main(String... args) {

    long start = System.currentTimeMillis();
    System.out.println("Start time: " + start);

    long MAX_VALUE_TO_CALCULATE = Long.parseLong(args[0]);
    Map<Long, Long> foundPairs = new HashMap<>();

    findEuler45(MAX_VALUE_TO_CALCULATE, foundPairs);

    long end = System.currentTimeMillis();
    System.out.println("End time: " + end);
    System.out.println("Calculation took: " + (end - start) + "millis");
  }

  private static void findEuler45(long max, Map<Long, Long> foundPairs) {
    Map<Long, Long> triangleBuckets = new HashMap<>(((int) max) * 2);
    Map<Long, Long> pentagonalBuckets = new HashMap<>();
    for (long t = 0; t < max; t++) {
      triangleBuckets.put(calcTriangle(t), t);
    }

    for (long p = 0; p < max; p++) {
      long pentagonal = calcPentagonal(p);
      if (triangleBuckets.containsKey(pentagonal)) {
        pentagonalBuckets.put(pentagonal, p);
      }
    }

    for (long h = 0; h < max; h++) {
      long hexagonal = calcHexagonal(h);
      if (pentagonalBuckets.containsKey(hexagonal)) {
        System.out.println(
            "Found value: " + hexagonal + " with inidices: Triangle: " + triangleBuckets.get(hexagonal) +
            " Pentagonal: " + foundPairs.get(hexagonal) + " Hexagonal: " + h);
      }
    }
  }

  private static long calcTriangle(long n) {
    return n * (n + 1) / 2;
  }

  private static long calcPentagonal(long n) {
    return n * (3 * n - 1) / 2;
  }

  private static long calcHexagonal(long n) {
    return n * (2 * n - 1);
  }
}

@@ -349,58 +349,8 @@
 0%5D);
-%0A    Map%3CLong, Long%3E foundPairs = new HashMap%3C%3E();
 %0A%0A  
@@ -389,20 +389,8 @@
 LATE
-, foundPairs
 );%0A%0A
@@ -600,36 +600,8 @@
  max
-, Map%3CLong, Long%3E foundPairs
 ) %7B%0A
@@ -1312,17 +1312,24 @@
 %22 + 
-foundPair
+pentagonalBucket
 s.ge

Remove Redundant Code