package UE10_070125_Rekursion3;

import java.util.ArrayList;
import java.util.List;

public class UE10_Rekursion3_Aufgabe2 {
    public static void main(String[] args) {
        //Aufgabe 2
        System.out.println("\n(9,3)");
        summingUp(9, 3, new ArrayList<>());
        System.out.println("\n(9,2)");
        summingUp(9, 2, new ArrayList<>());
        System.out.println("\n(45,9)");
        summingUp(45, 9, new ArrayList<>());
        System.out.println("\n(28,4)");
        summingUp(28, 4, new ArrayList<>());
    }

    public static void summingUp(int number, int count, List<Integer> list) {
        if (number == 0 && count == 0) {
            System.out.println(list.toString().replaceAll("\\D", ""));
            return;
        }
        if (number <= 0 || count <= 0) return;
        int start = 9;
        if (!list.isEmpty()) start = list.getLast() - 1;
        for (int i = start; i >= 1; i--) {
            list.add(i);
            summingUp(number - i, count - 1, list);
            list.removeLast();
        }
    }
}
