@@ -0,0 +1,1478 @@
+package tzhai.euler;%0D%0A%0D%0Aimport java.util.ArrayList;%0D%0A%0D%0A/**Problem 24 Lexicographic permutations%0D%0A * %0D%0A * A permutation is an ordered arrangement of objects. For example, 3124 is one%0D%0A * possible permutation of the digits 1, 2, 3 and 4. If all of the permutations%0D%0A * are listed numerically or alphabetically, we call it lexicographic order. The%0D%0A * lexicographic permutations of 0, 1 and 2 are:%0D%0A * %0D%0A * 012 021 102 120 201 210%0D%0A * %0D%0A * What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4,%0D%0A * 5, 6, 7, 8 and 9?%0D%0A * %0D%0A * @author Zhai Tengfei%0D%0A *%0D%0A */%0D%0A%0D%0Apublic class Problem25 %7B%0D%0A%09private static ArrayList%3CInteger%3E lexicographicPermutations(int n) %7B%0D%0A%09%09int order = n;%0D%0A%09%09ArrayList%3CInteger%3E result = new ArrayList%3CInteger%3E();%0D%0A%09%09int%5B%5D factorial = new int%5B9%5D;%0D%0A%09%09for (int i = 9; i %3E= 1; i--) %7B%0D%0A%09%09%09int temp = 1;%0D%0A%09%09%09for (int j = i; j %3E= 1; j--) %7B%0D%0A%09%09%09%09temp *= j;%0D%0A%09%09%09%7D%0D%0A%09%09%09factorial%5B9-i%5D = temp;%0D%0A%09%09%7D%0D%0A%09%09%0D%0A%09%09ArrayList%3CInteger%3E digits = new ArrayList%3CInteger%3E();%0D%0A%09%09for (int i = 0; i %3C 10; i++) %7B%0D%0A%09%09%09digits.add(i);%0D%0A%09%09%7D%0D%0A%09%09%0D%0A%09%09while (order != 1) %7B%0D%0A%09%09%09for (int i = 0; i %3C 9; i++) %7B%0D%0A%09%09%09%09for (int j = 1; j %3C 11-i; j++) %7B%0D%0A%09%09%09%09%09if ((factorial%5Bi%5D*j) %3E= order) %7B%0D%0A    %09%09%09%09%09%09result.add(digits.remove(j-1));%0D%0A%09%09%09%09%09%09order -= factorial%5Bi%5D*(j-1);%0D%0A%09%09%09%09%09%09break;%0D%0A%09%09%09%09%09%7D%0D%0A%09%09%09%09%7D%0D%0A%09%09%09%7D%0D%0A%09%09%7D%0D%0A%09%09result.add(digits.get(0));%09%0D%0A%09%09return result;%0D%0A%09%7D%0D%0A%09%0D%0A%09public static void main(String%5B%5D args) %7B%0D%0A%09%09System.out.println(Problem25.lexicographicPermutations(1000000));%0D%0A%09%7D%0D%0A%0D%0A%7D%0D%0A

Test commit