Skip to main content
1 of 2
user avatar
user avatar

Java, 66 bytes

For once, lambdas are the inefficient approach to golfing due to the very roundabout way of applying recursion to them that requires a lot of extra bytes.

Golfed:

String f(int m,int n,int p){return""+m+(p>1?","+f(n,m-n,p-1):"");}

Ungolfed:

public class CounterFibonacciSequences {

  private static final int[][] INPUTS = new int[][] { //
      { 50, 40, 10 }, //
      { -100, -90, 7 }, //
      { 250, 10, 8 } };

  private static final String[] OUTPUTS = new String[] { //
      "50,40,10,30,-20,50,-70,120,-190,310", //
      "-100,-90,-10,-80,70,-150,220", //
      "250,10,240,-230,470,-700,1170,-1870" };

  public static void main(String[] args) {
    for (int i = 0; i < INPUTS.length; ++i) {
      final int m = INPUTS[i][0];
      final int n = INPUTS[i][1];
      final int p = INPUTS[i][2];
      System.out.println("M: " + m);
      System.out.println("N: " + n);
      System.out.println("P: " + p);
      System.out.println("Expected: " + OUTPUTS[i]);
      System.out.println("Actual:   " + new CounterFibonacciSequences().f(m, n, p));
      System.out.println();
    }
  }

  String f(int m, int n, int p) {
    return "" + m + (p > 1 ? "," + f(n, m - n, p - 1) : "");
  }
}
user18932