(int[] permutation, int length, boolean even)
| 113 | |
| 114 | // permutation |
| 115 | public static int permToIdx(int[] permutation, int length, boolean even) { |
| 116 | int index = 0; |
| 117 | int end = even ? length - 2 : length - 1; |
| 118 | for (int i = 0; i < end; i++) { |
| 119 | index *= length - i; |
| 120 | for (int j = i + 1; j < length; j++) |
| 121 | if (permutation[i] > permutation[j]) index++; |
| 122 | } |
| 123 | return index; |
| 124 | } |
| 125 | |
| 126 | public static void idxToPerm(int[] permutation, int index, int length, boolean even) { |
| 127 | int sum = 0; |