package math.entropia;

import math.kombi.RXXX;
import math.utils.FrequencyMap;
import math.utils.MathUtil;

import java.util.Arrays;

public class Rozmieszczenie8_4_2 {
    public static final String[] urny = {"A", "A", "B", "C", "D", "E", "F", "G"};
    public static final int[] kule = {1, 1, 2, 3, 4, 5, 6, 7};

    public static void main(String[] args) {
        int liczbaPowt = 2700000;
        int n = 3;//liczba kul
        boolean ko = false;//kule odróżnialne?
        int k = 3;//liczba urn
        boolean uo = false;//urny odróżnialne?
        int nr = rows(k, uo, n, ko);
        System.out.println(nr);
        FrequencyMap<String> map = new FrequencyMap<>();
        if (ko && uo) {
            while (map.getSize() != nr) {
                for (int j = 0; j < liczbaPowt; j++) {
                    int[] kule = fillN(n);
                    String[] urny = fillL(k);
                    for (int i1 : kule) {
                        int r = MathUtil.randomInRange(0, k - 1);
                        urny[r] = urny[r].concat(String.valueOf(i1));
                    }
                    map.add(Arrays.toString(urny));
                }
            }
            map.printAll();
        } else if (!ko && uo) {
            while (map.getSize() != nr) {
                for (int j = 0; j < liczbaPowt; j++) {
                    int[] kule = new int[n];
                    Arrays.fill(kule, 1);
                    String[] urny = fillL(k);
                    for (int i1 : kule) {
                        int r = MathUtil.randomInRange(0, k - 1);
                        urny[r] = urny[r].concat(String.valueOf(i1));
                    }
                    map.add(Arrays.toString(urny));
                }
            }
            map.printAll();
        } else if (ko && !uo) {
            while (map.getSize() != nr) {
                for (int j = 0; j < liczbaPowt; j++) {
                    int[] kule = fillN(n);
                    String[] urny = new String[k];
                    Arrays.fill(urny, "A");
                    for (int i1 : kule) {
                        int r = MathUtil.randomInRange(0, k - 1);
                        urny[r] = urny[r].concat(String.valueOf(i1));
                    }
                    Arrays.sort(urny);
                    map.add(Arrays.toString(urny));
                }
            }
            map.printAll();
        } else if (!ko && !uo) {
            while (map.getSize() != nr) {
                for (int j = 0; j < liczbaPowt; j++) {
                    int[] kule = new int[n];
                    Arrays.fill(kule, 1);
                    String[] urny = new String[k];
                    Arrays.fill(urny, "A");
                    for (int i1 : kule) {
                        int r = MathUtil.randomInRange(0, k - 1);
                        urny[r] = urny[r].concat(String.valueOf(i1));
                    }
                    Arrays.sort(urny);
                    map.add(Arrays.toString(urny));
                }
            }
            map.printAll();
        }
    }

    public static int[] fillN(int number) {
        int[] tabl = new int[number];
        for (int i = 0; i < tabl.length; i++) {
            tabl[i] = kule[i + 1];
        }
        return tabl;
    }

    public static String[] fillL(int number) {
        String[] tabl = new String[number];
        for (int i = 0; i < tabl.length; i++) {
            tabl[i] = urny[i + 1];
        }
        return tabl;
    }

    public static int rows(int k, boolean uo, int n, boolean ko) {
        if (ko && uo) {
            return RXXX.r111(k, n);
        } else if (ko && !uo) {
            return RXXX.r101(k, n);
        } else if (!ko && uo) {
            return RXXX.r011(k, n);
        } else if (!ko && !uo) {
            return RXXX.r001(k, n);
        }
        return -1;
    }

}
