package de.sebhn.algorithm.excercise2;

import java.math.BigInteger;

public class Quaternstrings {

  private int n;
  private BigInteger[] currentPairs;

  public Quaternstrings(int n) {
    this.n = n;
    this.currentPairs =
        new BigInteger[] {BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE};
    System.out.println("n=" + n);
  }

  public static void main(String[] args) throws Exception {
    Quaternstrings.calculate(2);
  }

  public static BigInteger calculate(int n) {
    return new Quaternstrings(n).calculate();
  }

  private BigInteger calculate() {
    for (int i = 1; i < n; i++) {
      addInPlace();
    }
    BigInteger amountOfPaths = getAmountOfPaths();
    System.out.println("Amount of paths: " + amountOfPaths);
    return amountOfPaths;
  }

  private BigInteger getAmountOfPaths() {
    BigInteger a0 = currentPairs[0];
    BigInteger a1 = currentPairs[1];
    BigInteger a2 = currentPairs[2];
    BigInteger a3 = currentPairs[3];

    BigInteger amountOfPaths = a0.add(a1).add(a2).add(a3);
    return amountOfPaths;
  }

  private void addInPlace() {
    BigInteger a0 = currentPairs[0];
    BigInteger a1 = currentPairs[1];
    BigInteger a2 = currentPairs[2];
    BigInteger a3 = currentPairs[3];

    BigInteger newa0 = a0.add(a2).add(a3); // exclude 1
    BigInteger newa1 = a1.add(a0).add(a3); // exclude 2
    BigInteger newa2 = a2.add(a0).add(a1); // exclude 3
    BigInteger newa3 = a3.add(a0).add(a1).add(a2); // every number allowed

    currentPairs[0] = newa0;
    currentPairs[1] = newa1;
    currentPairs[2] = newa2;
    currentPairs[3] = newa3;
  }
}

@@ -142,193 +142,183 @@
 eger
-%5B%5D currentPairs;%0D%0A%0D%0A  public Quaternstrings(int n) %7B%0D%0A    this.n = n;%0D%0A    this.currentPairs =%0D%0A        new BigInteger%5B%5D %7BBigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE%7D
+ a0;%0D%0A  private BigInteger a1;%0D%0A  private BigInteger a2;%0D%0A  private BigInteger a3;%0D%0A%0D%0A  public Quaternstrings(int n) %7B%0D%0A    this.n = n;%0D%0A    a0 = a1 = a2 = a3 = BigInteger.ONE
 ;%0D%0A 
@@ -871,423 +871,115 @@
 er a
-0 = currentPairs%5B0%5D;%0D%0A    BigInteger a1 = currentPairs%5B1%5D;%0D%0A    BigInteger a2 = currentPairs%5B2%5D;%0D%0A    BigInteger a3 = currentPairs%5B3%5D;%0D%0A%0D%0A    BigInteger amountOfPaths = a0.add(a1).add(a2).add(a3);%0D%0A    return amountOfPaths;%0D%0A  %7D%0D%0A%0D%0A  private void addInPlace() %7B%0D%0A    BigInteger a0 = currentPairs%5B0%5D;%0D%0A    BigInteger a1 = currentPairs%5B1%5D;%0D%0A    BigInteger a2 = currentPairs%5B2%5D;%0D%0A    BigInteger a3 = currentPairs%5B3%5D;%0D%0A
+mountOfPaths = a0.add(a1).add(a2).add(a3);%0D%0A    return amountOfPaths;%0D%0A  %7D%0D%0A%0D%0A  private void addInPlace() %7B
 %0D%0A  
@@ -1233,113 +1233,61 @@
     
-currentPairs%5B0%5D = newa0;%0D%0A    currentPairs%5B1%5D = newa1;%0D%0A    currentPairs%5B2%5D = newa2;%0D%0A    currentPairs%5B3%5D
+a0 = newa0;%0D%0A    a1 = newa1;%0D%0A    a2 = newa2;%0D%0A    a3
  = n

replace array with 4 bigintegers