import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.*;

public class TestGen {

    static final ArrayList<String> STRATS = new ArrayList<String>() {{
        add("Random");
        add("HelpingHand");
        add("Spoiler");
        add("Swap12");
    }};

    static Random rnd = new Random(3);

    static interface PermutationGenerator {
        int[] gen(int n);
    }

    static PermutationGenerator[] GENS = new PermutationGenerator[] {
            new PermutationGenerator() {
                @Override
                public int[] gen(int n) {
                    int[] a = new int[n];
                    for (int i = 0; i < n; i++) {
                        a[i] = i;
                    }
                    return a;
                }
            },
            new PermutationGenerator() {
                @Override
                public int[] gen(int n) {
                    int[] a = new int[n];
                    for (int i = 0; i < n; i++) {
                        a[n - i - 1] = i;
                    }
                    return a;
                }
            },
            new PermutationGenerator() {
                @Override
                public int[] gen(int n) {
                    ArrayList<Integer> res = new ArrayList<>();
                    for (int i = 0; i < n; i++) {
                        res.add(i);
                    }
                    Collections.shuffle(res, rnd);
                    int[] a = new int[n];
                    for (int i = 0; i < n; i++) {
                        a[i] = res.get(i);
                    }
                    return a;
                }
            }
    };

    static int[] SIZES = new int[] {2, 5, 10, 100};

    final static int MAX_SUM_N = 1_000_000;

    static class TestWriter {
        final String root;
        int tests = 0;

        TestWriter(String path) {
            File root = new File(path);
            if (!root.exists()) {
                System.err.println("Creating directory <" + path + ">");
                root.mkdirs();
            }
            this.root = path;
        }

        void write(Test t) throws FileNotFoundException {
            String testNo = String.format("%02d", ++tests);
            PrintWriter out = new PrintWriter(root + "/" + testNo);
            System.err.println("Writing test (" + root + ") #" + testNo);
            out.println(t.strat);
            out.println(t.seed);
            out.println(t.n);
            for (int i = 0; i < t.p.length; i++) {
                out.print(t.p[i]);
                if (i != t.p.length - 1) {
                    out.print(" ");
                }
            }
            out.println();
            out.close();
        }
    }

    static class Test {
        Test(String strat, int seed, int... a) {
            this.strat = strat;
            this.seed = seed;
            n = a.length;
            p = a.clone();
        }

        final int n;
        final int seed;
        final int[] p;
        final String strat;

        @Override
        public String toString() {
            StringBuilder res = new StringBuilder();
            res.append(n).append("\n");
            for (int i : p) {
                res.append(i).append(" ");
            }
            res.append("\n");
            return res.toString();
        }
    }

    static Test test(String strat, int seed, int... t) {
        return new Test(strat, seed, t);
    }

    public static void main(String[] args) throws FileNotFoundException {
        final Random rnd = new Random(3);
        TestWriter tests = new TestWriter("../tests");
        tests.write(test("Random", 1, 2, 1, 0));
        for (String strat : STRATS) {
            for (PermutationGenerator gen : GENS) {
                for (int size : SIZES) {
                    tests.write(test(strat, rnd.nextInt(), gen.gen(size)));
                }
            }
        }
    }
}
