package de.sebhn.algorithm.excercise1;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
import java.util.stream.Collectors;

import de.sebhn.algorithm.excercise1.helper.Grid;
import de.sebhn.algorithm.excercise1.helper.PositionToIntConverter;

public class OutputCounter {

  private final List<Integer> intPositions;
  private final PositionToIntConverter positionToIntConverter;
  private int size;
  private boolean pathPrintingMakesSense;
  private Grid grid;

  public OutputCounter(Grid grid) {
    this.grid = grid;
    this.positionToIntConverter = grid.getConverter();
    pathPrintingMakesSense = grid.getSize() < 50;
    intPositions = new ArrayList<>();
  }

  public void addStack(Stack<Integer> stack) {
    if (pathPrintingMakesSense) {
      intPositions.addAll(stack);
    }
    size++;
  }

  public void printSize() {
    System.out.println("Possible Paths: " + size);
  }

  public void printPaths() {
    if (pathPrintingMakesSense) {
      String path = intPositions.stream()
          .map(pathElement -> getPositionToIntConverter().deConvert(pathElement).toString()) //
          .collect(Collectors.joining("->"));
      String endPath = grid.getTargetNumber() + "," + grid.getTargetNumber();
      path = path.replace(endPath + "->", endPath + "\n");
      System.out.println("Paths: \n" + path);
    } else {
      System.out.println("too much paths to print");
    }
  }

  public PositionToIntConverter getPositionToIntConverter() {
    return positionToIntConverter;
  }
}

@@ -33,16 +33,45 @@
 cise1;%0A%0A
+import java.math.BigInteger;%0A
 import j
@@ -86,24 +86,24 @@
 .ArrayList;%0A
-
 import java.
@@ -440,19 +440,26 @@
 private 
-int
+BigInteger
  size;%0A 
@@ -860,10 +860,28 @@
 size
-++
+.add(BigInteger.ONE)
 ;%0A  

use biginteger instead of int