@@ -0,0 +1,1825 @@
+package ru.permutation;%0A%0Aimport org.junit.Test;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.Collections;%0Aimport java.util.List;%0A%0Aimport static java.util.Arrays.asList;%0Aimport static org.hamcrest.CoreMatchers.equalTo;%0Aimport static org.junit.Assert.assertThat;%0A%0A/**%0A * User: DKandalov%0A */%0Apublic class Perm0%0A%7B%0A    @Test%0A    public void aaa()%0A    %7B%0A        assertThat(perm(Collections.%3CInteger%3EemptyList()), equalTo(asList(Arrays.%3CInteger%3EasList())));%0A        assertThat(perm(asList(1)), equalTo(asList(asList(1))));%0A        assertThat(perm(asList(1, 2)), equalTo(asList(asList(1, 2), asList(2, 1))));%0A        assertThat(perm(asList(1, 2, 3)), equalTo(asList(%0A                asList(1, 2, 3), asList(1, 3, 2), asList(3, 1, 2),%0A                asList(2, 1, 3), asList(2, 3, 1), asList(3, 2, 1)%0A        )));%0A    %7D%0A%0A    private List%3CList%3CInteger%3E%3E perm(List%3CInteger%3E values)%0A    %7B%0A        List%3CList%3CInteger%3E%3E result = new ArrayList%3CList%3CInteger%3E%3E();%0A        if (values.isEmpty()) %7B%0A            result.add(new ArrayList%3CInteger%3E());%0A            return result;%0A        %7D%0A%0A        values = new ArrayList%3CInteger%3E(values);%0A%0A        int index = values.size() - 1;%0A%0A        int steps = factorial(values.size());%0A        for (int i = 0; i %3C steps; i++) %7B%0A            result.add(new ArrayList%3CInteger%3E(values));%0A%0A            if (index %3C 0) index = values.size() - 1;%0A            int leftIndex = index - 1;%0A            if (leftIndex %3C 0) leftIndex = values.size() - 1;%0A%0A            int tmp = values.get(index);%0A            values.set(index, values.get(leftIndex));%0A            values.set(leftIndex, tmp);%0A%0A            index--;%0A        %7D%0A%0A        return result;%0A    %7D%0A%0A    private int factorial(int i)%0A    %7B%0A        if (i == 0) return 0;%0A        if (i == 1) return 1;%0A        return factorial(i - 1) * i;%0A    %7D%0A%7D%0A

permutation 0