(int[] permutation, int index, int length, boolean even)
| 124 | } |
| 125 | |
| 126 | public static void idxToPerm(int[] permutation, int index, int length, boolean even) { |
| 127 | int sum = 0; |
| 128 | if (even) { |
| 129 | permutation[length - 1] = 1; |
| 130 | permutation[length - 2] = 0; |
| 131 | } else permutation[length - 1] = 0; |
| 132 | int start = even ? length - 3 : length - 2; |
| 133 | for (int i = start; i >= 0; i--) { |
| 134 | permutation[i] = index % (length - i); |
| 135 | sum += permutation[i]; |
| 136 | index /= length - i; |
| 137 | for (int j = i + 1; j < length; j++) |
| 138 | if (permutation[j] >= permutation[i]) permutation[j]++; |
| 139 | } |
| 140 | if (even && sum % 2 != 0) { |
| 141 | swap(permutation, length - 1, length - 2); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | // flip |
| 146 | public static int flipToIdx(int[] flip, int length, boolean zeroSum) { |
no test coverage detected